client

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNetworkError

func IsNetworkError(err error) bool

func IsNotFoundError

func IsNotFoundError(err error) bool

func IsUnauthorizedError

func IsUnauthorizedError(err error) bool

Types

type APIError

type APIError struct {
	Code    int
	Message string
}

APIError Answer API 错误

func (*APIError) Error

func (e *APIError) Error() string

type AnswerService

type AnswerService struct {
	// contains filtered or unexported fields
}

func NewAnswerService

func NewAnswerService(client *Client) *AnswerService

func (*AnswerService) Accept

func (s *AnswerService) Accept(ctx context.Context, questionID, answerID string) error

func (*AnswerService) Add

func (*AnswerService) Delete

func (s *AnswerService) Delete(ctx context.Context, id string) error

func (*AnswerService) Get

func (*AnswerService) Page

func (*AnswerService) Update

type AuthService

type AuthService struct {
	// contains filtered or unexported fields
}

func NewAuthService

func NewAuthService(client *Client) *AuthService

func (*AuthService) GetCurrentUser

func (s *AuthService) GetCurrentUser(ctx context.Context) (*models.UserInfoResp, error)

func (*AuthService) IsAuthenticated

func (s *AuthService) IsAuthenticated() bool

func (*AuthService) Login

func (s *AuthService) Login(ctx context.Context, email, pass string) (*models.LoginResponse, error)

func (*AuthService) Logout

func (s *AuthService) Logout(ctx context.Context) error

type Client

type Client struct {
	Comment      *CommentService
	Tag          *TagService
	Search       *SearchService
	Notification *NotificationService
	User         *UserService
	Vote         *VoteService
	Question     *QuestionService
	Answer       *AnswerService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *Config) *Client

func (*Client) DeleteJSON

func (c *Client) DeleteJSON(ctx context.Context, path string, body interface{}) error

DeleteJSON DELETE 请求并解包 RespBody

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, path string, params map[string]string, result interface{}) error

GetJSON GET 请求并解包 RespBody

func (*Client) GetToken

func (c *Client) GetToken() string

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, body interface{}, result interface{}) error

PostJSON POST 请求并解包 RespBody

func (*Client) PutJSON

func (c *Client) PutJSON(ctx context.Context, path string, body interface{}, result interface{}) error

PutJSON PUT 请求并解包 RespBody

func (*Client) SetToken

func (c *Client) SetToken(token string)

type CommentService

type CommentService struct {
	// contains filtered or unexported fields
}

func NewCommentService

func NewCommentService(client *Client) *CommentService

func (*CommentService) Add

func (*CommentService) Delete

func (s *CommentService) Delete(ctx context.Context, id string) error

func (*CommentService) Get

func (*CommentService) Page

func (*CommentService) Update

type Config

type Config struct {
	BaseURL string
	Token   string
	Timeout time.Duration
}

type NotificationService

type NotificationService struct {
	// contains filtered or unexported fields
}

func NewNotificationService

func NewNotificationService(client *Client) *NotificationService

func (*NotificationService) ClearAll

func (s *NotificationService) ClearAll(ctx context.Context, nType string) error

func (*NotificationService) ClearID

func (s *NotificationService) ClearID(ctx context.Context, id string) error

func (*NotificationService) Page

func (*NotificationService) Status

type QuestionService

type QuestionService struct {
	// contains filtered or unexported fields
}

func NewQuestionService

func NewQuestionService(client *Client) *QuestionService

func (*QuestionService) Add

func (*QuestionService) Close

func (s *QuestionService) Close(ctx context.Context, id string, closeType int, closeMsg string) error

func (*QuestionService) Delete

func (s *QuestionService) Delete(ctx context.Context, id string) error

func (*QuestionService) Get

func (*QuestionService) Page

func (*QuestionService) Reopen

func (s *QuestionService) Reopen(ctx context.Context, id string) error

func (*QuestionService) Update

type RespBody

type RespBody struct {
	Code    int             `json:"code"`
	Reason  string          `json:"reason"`
	Message string          `json:"msg"`
	Data    json.RawMessage `json:"data"`
}

RespBody Answer API 统一响应结构

type SearchService

type SearchService struct {
	// contains filtered or unexported fields
}

func NewSearchService

func NewSearchService(client *Client) *SearchService

func (*SearchService) Search

type TagService

type TagService struct {
	// contains filtered or unexported fields
}

func NewTagService

func NewTagService(client *Client) *TagService

func (*TagService) Add

func (*TagService) Delete

func (s *TagService) Delete(ctx context.Context, slugName string) error

func (*TagService) Get

func (s *TagService) Get(ctx context.Context, slugName string) (*models.TagDetail, error)

func (*TagService) Page

func (*TagService) Search

func (s *TagService) Search(ctx context.Context, prefix string) ([]*models.TagItem, error)

func (*TagService) Update

func (s *TagService) Update(ctx context.Context, req *models.TagUpdateReq) error

type UserService

type UserService struct {
	// contains filtered or unexported fields
}

UserService 用户服务

func NewUserService

func NewUserService(client *Client) *UserService

NewUserService 创建用户服务

func (*UserService) GetByUsername

func (s *UserService) GetByUsername(ctx context.Context) (*models.UserBasicInfo, error)

GetByUsername 获取当前登录用户信息

func (*UserService) SearchUsers

func (s *UserService) SearchUsers(ctx context.Context, query string) ([]*models.UserBasicInfo, error)

SearchUsers 搜索用户

type VoteService

type VoteService struct {
	// contains filtered or unexported fields
}

func NewVoteService

func NewVoteService(client *Client) *VoteService

func (*VoteService) VoteDown

func (s *VoteService) VoteDown(ctx context.Context, objectID string) error

func (*VoteService) VoteUp

func (s *VoteService) VoteUp(ctx context.Context, objectID string) error

Jump to

Keyboard shortcuts

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