utils

package
v0.0.0-...-65e65ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultApiBase = "https://gitee.com/api/v5"
)

Variables

View Source
var (
	// Version gitee mcp server version
	Version = "0.1.11"
)

Functions

func CheckRequired

func CheckRequired(params map[string]interface{}, required ...string) (*mcp.CallToolResult, error)

func CombineOptions

func CombineOptions(options ...[]mcp.ToolOption) []mcp.ToolOption

func ConvertArgumentsToMap

func ConvertArgumentsToMap(arguments any) (map[string]interface{}, error)

ConvertArgumentsToMap 将 any 类型的参数安全转换为 map[string]interface{}

func GetApiBase

func GetApiBase() string

func GetGiteeAccessToken

func GetGiteeAccessToken() string

func IsAPIError

func IsAPIError(err error) bool

func IsAuthError

func IsAuthError(err error) bool

func IsNetworkError

func IsNetworkError(err error) bool

func IsParamError

func IsParamError(err error) bool

func SafelyConvertToInt

func SafelyConvertToInt(value interface{}) (int, error)

SafelyConvertToInt 尝试将各种类型安全地转换为 int 支持 int, int32, int64, float32, float64, string 类型的转换 对于浮点数,要求必须是整数值(如 1.0),不接受带小数部分的值 对于字符串,尝试解析为整数或浮点数(浮点数必须是整数值)

func SetApiBase

func SetApiBase(url string)

func SetGiteeAccessToken

func SetGiteeAccessToken(token string)

Types

type ErrMsgV5

type ErrMsgV5 struct {
	Message string `json:"message"`
}

type ErrorType

type ErrorType string
const (
	// ErrorTypeNetwork Network error
	ErrorTypeNetwork ErrorType = "network_error"
	// ErrorTypeAPI API error
	ErrorTypeAPI ErrorType = "api_error"
	// ErrorTypeAuth Auth error
	ErrorTypeAuth ErrorType = "auth_error"
	// ErrorTypeParam param error
	ErrorTypeParam ErrorType = "param_error"
	// ErrorTypeInternal Internal error
	ErrorTypeInternal ErrorType = "internal_error"
)

type GiteeClient

type GiteeClient struct {
	Url      string
	Method   string
	Payload  interface{}
	Headers  map[string]string
	Response *http.Response

	Query    map[string]string
	SkipAuth bool
	Ctx      context.Context
	// contains filtered or unexported fields
}

func NewGiteeClient

func NewGiteeClient(method, urlString string, opts ...Option) *GiteeClient

func (*GiteeClient) Do

func (g *GiteeClient) Do() (*GiteeClient, error)

func (*GiteeClient) GetRespBody

func (g *GiteeClient) GetRespBody() ([]byte, error)

func (*GiteeClient) HandleMCPResult

func (g *GiteeClient) HandleMCPResult(object any) (*mcp.CallToolResult, error)

func (*GiteeClient) IsFail

func (g *GiteeClient) IsFail() bool

func (*GiteeClient) IsSuccess

func (g *GiteeClient) IsSuccess() bool

func (*GiteeClient) SetHeaders

func (g *GiteeClient) SetHeaders(headers map[string]string) *GiteeClient

type GiteeError

type GiteeError struct {
	Type    ErrorType `json:"type"`
	Message string    `json:"message"`
	Code    int       `json:"code,omitempty"`
	Details string    `json:"details,omitempty"`
}

func NewAPIError

func NewAPIError(statusCode int, body []byte) *GiteeError

func NewAuthError

func NewAuthError() *GiteeError

func NewInternalError

func NewInternalError(err error) *GiteeError

func NewNetworkError

func NewNetworkError(err error) *GiteeError

func NewParamError

func NewParamError(param string, details string) *GiteeError

func (*GiteeError) Error

func (e *GiteeError) Error() string

type Option

type Option func(client *GiteeClient)

func WithContext

func WithContext(ctx context.Context) Option

func WithHeaders

func WithHeaders(headers map[string]string) Option

func WithPayload

func WithPayload(payload interface{}) Option

func WithQuery

func WithQuery(query map[string]interface{}) Option

func WithSkipAuth

func WithSkipAuth() Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL