1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-05 02:30:23 +08:00

reduce unsafe

This commit is contained in:
源文雨
2023-10-11 18:00:46 +09:00
parent 64f912e856
commit 58b8e7a98c
8 changed files with 19 additions and 29 deletions

View File

@@ -10,8 +10,6 @@ const head = `// Code generated by codegen/getopenapiof. DO NOT EDIT.
package nano
import (
"unsafe"
"github.com/pkg/errors"
)
`
@@ -26,7 +24,7 @@ func (bot *Bot) getOpenAPIof[T any](ep string) (*[T any], error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*[T any])(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.[T any], err
}
`

View File

@@ -11,7 +11,6 @@ package nano
import (
"io"
"unsafe"
"github.com/pkg/errors"
)
@@ -27,7 +26,7 @@ func (bot *Bot) patchOpenAPIof[T any](ep string, body io.Reader) (*[T any], erro
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*[T any])(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.[T any], err
}
`

View File

@@ -11,7 +11,6 @@ package nano
import (
"io"
"unsafe"
"github.com/pkg/errors"
)
@@ -27,7 +26,7 @@ func (bot *Bot) postOpenAPIof[T any](ep, contenttype string, body io.Reader) (*[
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*[T any])(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.[T any], err
}
`

View File

@@ -11,7 +11,6 @@ package nano
import (
"io"
"unsafe"
"github.com/pkg/errors"
)
@@ -27,7 +26,7 @@ func (bot *Bot) putOpenAPIof[T any](ep string, body io.Reader) (*[T any], error)
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*[T any])(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.[T any], err
}
`

View File

@@ -3,8 +3,6 @@
package nano
import (
"unsafe"
"github.com/pkg/errors"
)
@@ -17,7 +15,7 @@ func (bot *Bot) getOpenAPIofShardWSSGateway(ep string) (*ShardWSSGateway, error)
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*ShardWSSGateway)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.ShardWSSGateway, err
}
func (bot *Bot) getOpenAPIofUser(ep string) (*User, error) {
@@ -29,7 +27,7 @@ func (bot *Bot) getOpenAPIofUser(ep string) (*User, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*User)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.User, err
}
func (bot *Bot) getOpenAPIofGuild(ep string) (*Guild, error) {
@@ -41,7 +39,7 @@ func (bot *Bot) getOpenAPIofGuild(ep string) (*Guild, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Guild)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Guild, err
}
func (bot *Bot) getOpenAPIofChannel(ep string) (*Channel, error) {
@@ -53,7 +51,7 @@ func (bot *Bot) getOpenAPIofChannel(ep string) (*Channel, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Channel)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Channel, err
}
func (bot *Bot) getOpenAPIofMember(ep string) (*Member, error) {
@@ -65,7 +63,7 @@ func (bot *Bot) getOpenAPIofMember(ep string) (*Member, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Member)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Member, err
}
func (bot *Bot) getOpenAPIofRoleMembers(ep string) (*RoleMembers, error) {
@@ -77,7 +75,7 @@ func (bot *Bot) getOpenAPIofRoleMembers(ep string) (*RoleMembers, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*RoleMembers)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.RoleMembers, err
}
func (bot *Bot) getOpenAPIofGuildRoleList(ep string) (*GuildRoleList, error) {
@@ -89,7 +87,7 @@ func (bot *Bot) getOpenAPIofGuildRoleList(ep string) (*GuildRoleList, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*GuildRoleList)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.GuildRoleList, err
}
func (bot *Bot) getOpenAPIofChannelPermissions(ep string) (*ChannelPermissions, error) {
@@ -101,7 +99,7 @@ func (bot *Bot) getOpenAPIofChannelPermissions(ep string) (*ChannelPermissions,
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*ChannelPermissions)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.ChannelPermissions, err
}
func (bot *Bot) getOpenAPIofMessage(ep string) (*Message, error) {
@@ -113,5 +111,5 @@ func (bot *Bot) getOpenAPIofMessage(ep string) (*Message, error) {
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Message)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Message, err
}

View File

@@ -4,7 +4,6 @@ package nano
import (
"io"
"unsafe"
"github.com/pkg/errors"
)
@@ -18,7 +17,7 @@ func (bot *Bot) patchOpenAPIofChannel(ep string, body io.Reader) (*Channel, erro
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Channel)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Channel, err
}
func (bot *Bot) patchOpenAPIofGuildRolePatch(ep string, body io.Reader) (*GuildRolePatch, error) {
@@ -30,5 +29,5 @@ func (bot *Bot) patchOpenAPIofGuildRolePatch(ep string, body io.Reader) (*GuildR
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*GuildRolePatch)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.GuildRolePatch, err
}

View File

@@ -4,7 +4,6 @@ package nano
import (
"io"
"unsafe"
"github.com/pkg/errors"
)
@@ -18,7 +17,7 @@ func (bot *Bot) postOpenAPIofChannel(ep, contenttype string, body io.Reader) (*C
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Channel)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Channel, err
}
func (bot *Bot) postOpenAPIofGuildRoleCreate(ep, contenttype string, body io.Reader) (*GuildRoleCreate, error) {
@@ -30,7 +29,7 @@ func (bot *Bot) postOpenAPIofGuildRoleCreate(ep, contenttype string, body io.Rea
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*GuildRoleCreate)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.GuildRoleCreate, err
}
func (bot *Bot) postOpenAPIofMessage(ep, contenttype string, body io.Reader) (*Message, error) {
@@ -42,5 +41,5 @@ func (bot *Bot) postOpenAPIofMessage(ep, contenttype string, body io.Reader) (*M
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*Message)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.Message, err
}

View File

@@ -4,7 +4,6 @@ package nano
import (
"io"
"unsafe"
"github.com/pkg/errors"
)
@@ -18,5 +17,5 @@ func (bot *Bot) putOpenAPIofGuildRoleChannelID(ep string, body io.Reader) (*Guil
if err != nil {
err = errors.Wrap(err, getCallerFuncName())
}
return (*GuildRoleChannelID)(unsafe.Add(unsafe.Pointer(resp), unsafe.Sizeof(CodeMessageBase{}))), err
return &resp.GuildRoleChannelID, err
}