35 lines
849 B
Go
35 lines
849 B
Go
package main
|
|
|
|
func generateRequestDecoder() {
|
|
generateToFile(headerRequestDecoder, templateFuncRequestDecoder, "internal/apiproto/decode_request_gen.go", nil, nil)
|
|
}
|
|
|
|
var headerRequestDecoder = `// Code generated by internal/gen/api/main.go. DO NOT EDIT.
|
|
|
|
package apiproto
|
|
|
|
import "encoding/json"
|
|
|
|
var _ RequestDecoder = (*JSONRequestDecoder)(nil)
|
|
|
|
// JSONRequestDecoder ...
|
|
type JSONRequestDecoder struct{}
|
|
|
|
// NewJSONRequestDecoder ...
|
|
func NewJSONRequestDecoder() *JSONRequestDecoder {
|
|
return &JSONRequestDecoder{}
|
|
}
|
|
`
|
|
|
|
var templateFuncRequestDecoder = `
|
|
// Decode{{ .RequestCapitalized }} ...
|
|
func (d *JSONRequestDecoder) Decode{{ .RequestCapitalized }}(data []byte) (*{{ .RequestCapitalized }}Request, error) {
|
|
var p {{ .RequestCapitalized }}Request
|
|
err := json.Unmarshal(data, &p)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &p, nil
|
|
}
|
|
`
|