1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-05 02:30:23 +08:00
Files
NanoBot/codegen/putopenapiof/main.go
2023-10-11 18:00:46 +09:00

50 lines
801 B
Go

package main
import (
"os"
"strings"
)
const head = `// Code generated by codegen/putopenapiof. DO NOT EDIT.
package nano
import (
"io"
"github.com/pkg/errors"
)
`
const template = `
func (bot *Bot) putOpenAPIof[T any](ep string, body io.Reader) (*[T any], error) {
resp := &struct {
CodeMessageBase
[T any]
}{}
err := bot.PutOpenAPI(ep, "", resp, body)
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return &resp.[T any], err
}
`
func main() {
f, err := os.Create("openapi_codegen_putopenapiof.go")
if err != nil {
panic(err)
}
defer f.Close()
_, err = f.WriteString(head)
if err != nil {
panic(err)
}
for _, name := range os.Args[1:] {
_, err = f.WriteString(strings.ReplaceAll(template, "[T any]", name))
if err != nil {
panic(err)
}
}
}