I'm not too familiar with this in Go
type PageOffset int
type Page int
How would I create an instance of a struct using PageOffset
& Page
?
type GetParams struct {
Page *Page
PageOffset *PageOffset
}
I've tried something like this but I am getting this error
invalid composite literal type
p := GetParams{}
p.Page = &Page{1}
p.PageOffset = &PageOffset{10}
As Page and PageOffset are not structs but rather new type definitions with underlying int types, you should use it like when using int
directly
p := Page(1)
pO := PageOffset(2)
GetParams{
Page: &p,
PageOffset: &pO,
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.