utils

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

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

Variables

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

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 added in v0.1.8

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

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

func ConvertToHash

func ConvertToHash(params map[string]interface{}, key string, properties ...string) map[string]interface{}

func GetApiBase

func GetApiBase() string

func GetGiteeAccessToken

func GetGiteeAccessToken() string

func IsAPIError

func IsAPIError(err error) bool

func IsAllDigits

func IsAllDigits(s string) 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 SafelyConvertToString added in v0.1.6

func SafelyConvertToString(value interface{}) (string, error)

SafelyConvertToString 尝试将各种类型安全地转换为 string 支持 int, int32, int64, float32, float64, string, bool 类型的转换 对于数字类型,直接转换为对应的字符串表示 对于布尔值,转换为 "true" 或 "false"

func SetApiBase

func SetApiBase(url string)

func SetGiteeAccessToken

func SetGiteeAccessToken(token string)

Types

type Authorizer added in v0.1.4

type Authorizer interface {
	Authorize(req *http.Request) error
}

type BearerTokenAuthorizer added in v0.1.4

type BearerTokenAuthorizer struct{}

func (*BearerTokenAuthorizer) Authorize added in v0.1.4

func (b *BearerTokenAuthorizer) Authorize(req *http.Request) error

type CookieAuthorizer added in v0.1.4

type CookieAuthorizer struct {
	Cookie string
}

func (*CookieAuthorizer) Authorize added in v0.1.4

func (c *CookieAuthorizer) Authorize(req *http.Request) error

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
	// contains filtered or unexported fields
}

func NewGiteeClient

func NewGiteeClient(method, urlPath 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 WithApiBase added in v0.1.4

func WithApiBase(url string) Option

WithApiBase now modifies the client's internal apiBase field

func WithAuthorizer added in v0.1.4

func WithAuthorizer(authorizer Authorizer) Option

func WithHTTPClient added in v0.1.4

func WithHTTPClient(httpClient *http.Client) 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

type OptionHandlerFunc added in v0.1.4

type OptionHandlerFunc func(context.Context, mcp.CallToolRequest, ...Option) (*mcp.CallToolResult, error)

OptionHandlerFunc defines the signature for handlers that accept utils.Option.

Jump to

Keyboard shortcuts

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