snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
34
internal/gen/api/gen_request_decoder.go
Normal file
34
internal/gen/api/gen_request_decoder.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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
|
||||
}
|
||||
`
|
||||
Reference in New Issue
Block a user