Questions tagged [go-structtag]

25 questions
6
votes
1 answer

Handling nested struct in Go Validator.v2

I have been using Go Validator.v2 for field validations and it works elegantly for my non-struct typed fields. However, when it comes to handling struct-based fields (within the original struct), there is no documentation about it whatsoever.…
DevO
  • 133
  • 2
  • 8
6
votes
1 answer

encoding/json unmarshal missing a field

The following code unmarshal's the "Id", but not the "Hostname". Why? I've been staring at it for long enough now that if it's a typo I know I'll never spot it. Help please. (http://play.golang.org/p/DIRa2MvvAV) package main import ( …
Ask Bjørn Hansen
  • 6,784
  • 2
  • 26
  • 40
3
votes
1 answer

How to marshal struct as if it were an anonymous struct?

The documentation states: Anonymous struct fields are usually marshaled as if their inner exported fields were fields in the outer struct. For examble: type foo struct { Foo1 string `json:"foo1"` Foo2 string `json:"foo2"` } type boo…
Fotiadis M.
  • 95
  • 1
  • 12
2
votes
1 answer

Add bson tags to the go struct using GoModifyTags

I am trying to use GoModifyTags but it's not giving me required result. I have installed this as per the instruction but don't know how to implement. Using VScode editor. I am trying to add bson tags in my file. Currently, I have: type option…
Muhammad Tariq
  • 3,318
  • 5
  • 38
  • 42
1
vote
0 answers

Implementing grpc in gnark v0.8.1, how to convert Proof, Verification Key & Public Witness to go-native type?

In gnark v0.8.1, We first need to convert those 3 to go-native i.e. we convert them to []byte. I tried implementing Serialize() and DeSerialize(), but I am facing errors. Issue: groth16.Proof is an interface and its implementation depends upon…
1
vote
1 answer

parse nested json using struct in go language

Unable to parse nested json into structs objects using go lang I have a nested json string that I want to parse using struct in Go language. The json looks like…
Byte
  • 37
  • 4
1
vote
0 answers

Baked-in validation to return an error if the request body contains a specific field in Go

I am using go struct validator library https://github.com/go-playground/validator to validate struct which is used to decode the request body of a patch request. I want return an error if a specific field is present in the request. I can do this by…
Asitha
  • 35
  • 4
1
vote
2 answers

How to unmarshall time string into time.Time in golang?

I am reading data from multiple tables using JOIN, CONCAT, GROUP_CONCAT, JSON_OBJECT. The data is read into the below mentioned model using gorm. type OrgUserDisPublisherData struct { Disciplines datatypes.JSON `json:"disciplines" example:"[]"` …
Midhun Kumar
  • 549
  • 5
  • 23
1
vote
2 answers

Cannot read StructTag for some reason

I have this handler: func (h Handler) makeGetMany(v PeopleInjection) http.HandlerFunc { type RespBody struct { TypeCreatorMeta string `type:"bar",tc_resp_body_type:"true"` } type ReqBody struct { TypeCreatorMeta string…
user7898461
0
votes
2 answers

How to see tag key of json with go struct?

I am learning https://www.digitalocean.com/community/tutorials/how-to-use-json-in-go#using-a-struct-to-generate-json (old version of Go). I use go 1.20.1 , Windows 11 x64, GoLand 2022.3.2 . package sample3 import ( foo "encoding/json" …
Vy Do
  • 46,709
  • 59
  • 215
  • 313
0
votes
1 answer

JSON Arrays as Go Structs

I am trying to call an array of objects from my JSON file but I am always facing an error saying: "cannot unmarshal array into Go value of type config.APPConfig". How can I ensure the configs how my Go struct calls the array of objects within my…
Blerni2.0
  • 11
  • 3
0
votes
0 answers

Golang scan db rows to json of string and array

I am trying to get the output from DB using an inner join with 3 tables say Table A and B. Output Struct type C struct { A A `json:"A"` B B `json:"B"` SecID int64 `json:"section_id"` SecName …
aakash singh
  • 267
  • 5
  • 19
0
votes
1 answer

Golang use array values in db query to filter records

I have list of array int64 values ids = [{1} {2} {3}] I want to use the above array in db query to filter out the records where ID is not in above ids. SELECT * from table where id not in (1,2,3); I tried many ways to do but failing to make the…
aakash singh
  • 267
  • 5
  • 19
0
votes
1 answer

appending to YAML file using go lang

I writing a golang program which append rule to the file as mentioned below Required format: customRules: custom-rules.yaml: |- - rule: Pod Created in Kube Namespace append: true condition: and (k8s_audit_never_true) source:…
Sathya
  • 69
  • 2
  • 8
0
votes
2 answers

How to declare something like empty Object/Struct inside Struct?

Hi i am process of learning the Go language, and i want to ask how to create empty Object/Struct as domain model data type? i am using Fiber as my framework and here is the example of what i want to get from golang response api is something like…
Ke Vin
  • 3,478
  • 11
  • 60
  • 91
1
2