Files
upstream-centrifugo/internal/gen/api/gen_request_decoder.go
upstream-mirror b352a9a30d
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s
snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:17:21 +05:00

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
}
`