mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-05 18:50:24 +08:00
50 lines
801 B
Go
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)
|
|
}
|
|
}
|
|
}
|