Skip to content

Instantly share code, notes, and snippets.

@idoqo
Created June 24, 2020 10:32
Show Gist options
  • Save idoqo/de87d25944bb59be31a9288a6f179006 to your computer and use it in GitHub Desktop.
Save idoqo/de87d25944bb59be31a9288a6f179006 to your computer and use it in GitHub Desktop.
convert a moira dto struct to its json equivalent
package main
import (
"encoding/json"
"fmt"
"github.com/moira-alert/moira/api/dto"
"os"
"github.com/alecthomas/jsonschema"
)
func main() {
reflector := jsonschema.Reflector{
RequiredFromJSONSchemaTags: true,
ExpandedStruct: true,
}
marshaled, err := json.Marshal(reflector.Reflect(&dto.TagStatistics{}))
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Print(string(marshaled))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment