mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-05 18:50:24 +08:00
finish base
This commit is contained in:
50
codegen/getopenapiof/main.go
Normal file
50
codegen/getopenapiof/main.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const head = `// Code generated by codegen/getopenapiof. DO NOT EDIT.
|
||||
|
||||
package nano
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
`
|
||||
|
||||
const template = `
|
||||
func (bot *Bot) getOpenAPIof[T any](ep string) (*[T any], error) {
|
||||
resp := &struct {
|
||||
CodeMessageBase
|
||||
[T any]
|
||||
}{}
|
||||
err := bot.GetOpenAPI(ep, resp)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, getCallerFuncName())
|
||||
return nil, err
|
||||
}
|
||||
return (*[T any])(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), nil
|
||||
}
|
||||
`
|
||||
|
||||
func main() {
|
||||
f, err := os.Create("openapi_codegen_getopenapiof.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user