Skip to content

Instantly share code, notes, and snippets.

@yusufpapurcu
Created March 16, 2022 18:47
Show Gist options
  • Save yusufpapurcu/7ff8eb09ef14bd56f5db368a3f603173 to your computer and use it in GitHub Desktop.
Save yusufpapurcu/7ff8eb09ef14bd56f5db368a3f603173 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
)
func main() {
a := cover{Field1: "12323", Field2: "1213123", Field3: "321321", Field4: "123213", Field5: "21323", Field6: "123123"}
str, err := json.Marshal(a)
fmt.Println(string(str), "\nerr:", err)
}
type exampleStruct struct {
Field1, Field2, Field3, Field4, Field5, Field6 string
}
func getDefaultsexamplestruct() exampleStruct {
return exampleStruct{
Field1: "N/A", Field2: "N/A", Field3: "N/A", Field4: "N/A", Field5: "N/A", Field6: "N/A",
}
}
type cover exampleStruct
func (c cover) MarshalJSON() ([]byte, error) {
a := getDefaultsexamplestruct()
a.Field1 = c.Field1
a.Field2 = c.Field2
a.Field6 = c.Field6
return json.Marshal(a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment