Questions tagged [go-structtag]

25 questions
0
votes
1 answer

Unable to write a generic function that can work on multiple Structs in Golang

I am new to Go, and learning Interfaces and Structs. I am having 2 structs - ServiceSection and SliderSection and I am trying to accomplish the below 2 tasks with each of them- GET the JSON response and unmarshal it. Use the struct to create HTML…
Rahul Satal
  • 2,107
  • 3
  • 32
  • 53
0
votes
2 answers

How do I change the JSON tag within a Go struct?

I have a structure that looks like this type MediaFile struct { ID string `json:"id"` Secret string `json:"-"` Title string `json:"title"` } I want to be able to change…
BRSwift
  • 57
  • 5
0
votes
1 answer

How do I get a specific api by it's name and then get it's ID from this "Apis" list of structs?

type Apis struct { Items []struct { ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` CreatedDate int …
0
votes
1 answer

How to write a struct with nested recursive data in golang

I have data like following { "cars": { "toyota": [ "sedan", "pickup" ], "honda": [ "sedan", "couple", "pickup" ] .... } } The list…
wzcwts521
  • 15
  • 4
0
votes
0 answers

Is there any way I set omitempty by default for specific json.Encoder or in fallback on global configuration?

like type User struct { ID int32 `json:"_id"` Week string `json:"week"` } json.Marshal(&User{},true)//omitempty is true will return {} is bson,yaml,sql or any other library support this feature?
curtank
  • 600
  • 2
  • 7
  • 18
0
votes
1 answer

Can you set multiple (different) tags with the same value?

For some of my projects, I have had to use the viper package to use configuration. The package requires you to add the mapstructure:"fieldname" to identify and set your configuration object's fields correctly, but I have also had to add other tags…
Ocodenyth
  • 15
  • 3
-1
votes
1 answer

go reflect find by structtag

type A struct { Name *NameS `json:"name"` } for a struct A,is there a method in reflect that I can find a field by structtag like reflect.ValueOf(&ns) // struct s := ps.Elem() s.FieldByTag("name")
curtank
  • 600
  • 2
  • 7
  • 18
-2
votes
1 answer

structtag go package seems not change tags inside function

im working to this code: package main import ( "fmt" "reflect" "github.com/fatih/structtag" ) type Person struct { Name string `json:"name"` Age int `json:"age"` Address…
-2
votes
1 answer

Go - struct not visible in the same package but nested folder

I am working on a Go project with the structure as this: pages (folder) -> faculty (folder) > instructors.go > professors.go generalpages.go (inside pages folder) generalpages.go handles my Repository pattern struct with…
Patrick
  • 318
  • 3
  • 13
-2
votes
1 answer

Read Multiple json object from a json file in Go

I am trying to read the following json objects from the json file. So the number of objects are not predefined, they can be multiple or just one. So I tried making this struct but I am not able to read it properly. I want to parse the elements…
1
2