从Go中的函数返回struct

更新时间:2023-06-28 01:50:30 阅读: 评论:0

从Go中的函数返回struct
I'm trying to return a struct from one function to another for u with an API. The function is to reduce repeating my code in other places in my API that I am developing.
I'm getting the below error:
cannot u getProjectLocations(params) (type []ProjectLocation) as type []ProjectLocation in assignment
Code below:
func GetProject(w http.ResponWriter, r *http.Request) {
params := mux.Vars(r)["uuid"]
type ProjectLocation struct {
什么是世界语UUID    string `json:"uuid"`
Location string `json:"location"`
Primary  bool  `json:"is_primary"`
}
u盘在电脑上读不出来type Project struct {
UUID          string            `json:"uuid"`
Owner          null.String      `json:"project_owner"`
育人为本Name          string            `json:"project_name"`
Locations      []ProjectLocation `json:"locations"`
}
q := `SELECT
p.uuid,
p.project_owner,
p.project_name,
p.project_type,
p.project_status,
p.last_modified,
p.last_modified_by
FROM
projects p
WHERE p.uuid=$1 LIMIT 1;`
rows, err := global.DB.Query(q, params)
global.CheckDbErr(err)
var project Project
画歌词赵雷for rows.Next() {
err = rows.Scan(
&project.UUID,性感美女的照片
&project.Owner,
&project.Name,
)
global.CheckDbErr(err)
}
project.Locations = getProjectLocations(params)
rows.Clo()
json.NewEncoder(w).Encode(project)
}标准化车间
func getProjectLocations(uuid string) []ProjectLocation {
var Locations []ProjectLocation
q := `SELECT uuid,location,is_primary FROM project_locations WHERE project_uuid=$1`
rows, err := global.DB.Query(q, uuid)
global.CheckDbErr(err)
for rows.Next() {
var location ProjectLocation
err = rows.Scan(
形容寒冷的诗句&location.UUID,
&location.Location,
&location.Primary,
)
Locations = append(Locations, location)
}
return Locations
}
I believe I'm returning a []ProjectLocation struct to the get project function, so I'm just a little confud as a beginner.
>风景头像图片大全

本文发布于:2023-06-28 01:50:30,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1055452.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:电脑   美女   返回   车间   诗句   风景
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图