62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
|
// This file was autogenerated with autogenpb v0.5.6-2-gfabf425 2025-09-23_15:21:15_UTC
|
|
// go install go.wit.com/apps/autogenpb@latest
|
|
//
|
|
// define which structs (messages) you want to use in the .proto file
|
|
// Then sort.pb.go and marshal.pb.go files are autogenerated
|
|
//
|
|
// autogenpb uses it and has an example .proto file with instructions
|
|
//
|
|
|
|
package forgepb
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"go.wit.com/lib/protobuf/httppb"
|
|
)
|
|
|
|
// START HTTP
|
|
|
|
func (p *Patches) SendReply(w http.ResponseWriter, reqPB *httppb.HttpRequest) error {
|
|
data, err := p.Marshal()
|
|
if err != nil {
|
|
// reqPB.Errors = append(reqPB.Errors, log.Sprintf(, err))
|
|
}
|
|
if len(data) == 0 {
|
|
// reqPB.Errors = append(reqPB.Errors, "Patches PB data was nil/emtpy without Marsha() error")
|
|
return nil
|
|
}
|
|
_, err = w.Write(data)
|
|
if err != nil {
|
|
// reqPB.Errors = append(reqPB.Errors, log.Sprintf(, i, err))
|
|
}
|
|
return err
|
|
}
|
|
|
|
// Marshal protobuf, then http POST, then Unmarshal() to protobuf again
|
|
func (p *Patches) HttpPost(baseURL string, route string) (*Patches, *httppb.HttpRequest, error) {
|
|
data, err := p.Marshal()
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
tmp := filepath.Join("patches", route)
|
|
reqPB, err := httppb.DoPost(baseURL, tmp, data)
|
|
if reqPB == nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
if len(reqPB.ServerData) == 0 {
|
|
return nil, reqPB, fmt.Errorf("server returned len(data)=0")
|
|
}
|
|
|
|
newpb := new(Patches)
|
|
err = newpb.Unmarshal(reqPB.ServerData)
|
|
return newpb, reqPB, err
|
|
}
|
|
|
|
// END HTTP
|