apis

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Common errors
	OK                         = &Errno{Code: 10000, Message: "operation succeeded"}
	QUERY_NULL                 = &Errno{Code: 10003, Message: "request query is null"}
	NETWORK_MASQUERADE_ENABLE  = &Errno{Code: 10000, Message: "network masquerade is enable"}
	NETWORK_MASQUERADE_DISABLE = &Errno{Code: 10000, Message: "network masquerade is disable"}
	ErrDBus                    = "connect to remote firewalld server failed"
	InternalServerError        = &Errno{Code: 10001, Message: "Internal server error"}
	ErrBind                    = &Errno{Code: 10002, Message: "Error occurred while binding the request body to the struct"}
	ErrParam                   = &Errno{Code: 10003, Message: "参数有误"}
	ErrSignParam               = &Errno{Code: 10004, Message: "签名参数有误"}

	ErrValidation         = &Errno{Code: 20001, Message: "Validation failed"}
	ErrDatabase           = &Errno{Code: 20002, Message: "Database error"}
	ErrToken              = &Errno{Code: 20003, Message: "Error occurred while signing the JSON web token"}
	ErrInvalidTransaction = &Errno{Code: 20004, Message: "invalid transaction"}

	// NOTFOUNT
	ErrRichNotFount    = &Errno{Code: 40004, Message: "The rich rules in the zone is empty"}
	ErrServiceNotFount = &Errno{Code: 40004, Message: "The service in the zone is empty"}
	ErrPortNotFount    = &Errno{Code: 40004, Message: "The port in the zone is empty"}
	ErrZoneNotFount    = &Errno{Code: 40004, Message: "Not found the zone"}
	ErrForwardNotFount = &Errno{Code: 40004, Message: "The Forward in the zone is empty"}

	// token errors
	ErrEncrypt               = &Errno{Code: 50101, Message: "success"}
	ErrUserNotFound          = &Errno{Code: 50102, Message: "User not found"}
	ErrTokenInvalid          = &Errno{Code: 50103, Message: "Invalied token"}
	ErrPasswordIncorrect     = &Errno{Code: 50104, Message: "Incorrect username or password"}
	ErrUserExist             = &Errno{Code: 50105, Message: "User exists"}
	ErrUserNotExist          = &Errno{Code: 50106, Message: "User does not exist"}
	ErrNeedAuth              = &Errno{Code: 50107, Message: "Your need authetication"}
	ErrTokenDestoryed        = &Errno{Code: 50108, Message: "Token is destoryed"}
	ErrSendSMSTooMany        = &Errno{Code: 50109, Message: "已超出当日限制,请明天再试"}
	ErrVerifyCode            = &Errno{Code: 50110, Message: "验证码错误"}
	ErrEmailOrPassword       = &Errno{Code: 50111, Message: "邮箱或密码错误"}
	ErrTwicePasswordNotMatch = &Errno{Code: 50112, Message: "两次密码输入不一致"}
	ErrRegisterFailed        = &Errno{Code: 50113, Message: "注册失败"}
	ErrCreatedUser           = &Errno{Code: 50114, Message: "用户创建失败"}
	ErrDashboardFailed       = &Errno{Code: 50115, Message: "Get host status failed"}

	ErrTagNotFound   = &Errno{Code: 30104, Message: "Tag not found"}
	ErrTagExist      = &Errno{Code: 30106, Message: "Tag does existed"}
	ErrTemplateExist = &Errno{Code: 30106, Message: "Template does existed"}
	ErrExist         = &Errno{Code: 30106, Message: "Tag does existed"}

	BatchSuccessCreated = &Errno{Code: 60000, Message: "The batch mission has created"}
	BatchErrCreated     = &Errno{Code: 60005, Message: "The batch mission create failed"}
)

nolint: golint

Functions

func API404Response added in v0.0.3

func API404Response(ctx *gin.Context, err error)

404Response

func API409Response added in v0.0.3

func API409Response(ctx *gin.Context, err error)

409Response

func API500Response added in v0.0.3

func API500Response(ctx *gin.Context, err error)

400Response

func APIResponse added in v0.0.3

func APIResponse(ctx *gin.Context, err error, data interface{})

APIResponse ....

func Auth403Failed added in v0.0.3

func Auth403Failed(ctx *gin.Context, msg *Errno, data interface{})

API403Response ....

func AuthFailed added in v0.0.3

func AuthFailed(ctx *gin.Context, msg *Errno, data interface{})

func BacthMissionFailedResponse added in v0.0.3

func BacthMissionFailedResponse(ctx *gin.Context, err ...error)

ConnectDbusService ....

func BacthMissionSuccessResponse added in v0.0.3

func BacthMissionSuccessResponse(ctx *gin.Context, err error)

ConnectDbusService ....

func ConnectDbusService added in v0.0.3

func ConnectDbusService(ctx *gin.Context, err error)

ConnectDbusService ....

func DecodeErr

func DecodeErr(err error) (int, string)

DecodeErr ...

func DecodeErrSlice

func DecodeErrSlice(err ...error) (int, []string)

func NotFount added in v0.0.3

func NotFount(ctx *gin.Context, err error, data interface{})

NotFountResponse ....

func SuccessResponse added in v0.0.3

func SuccessResponse(ctx *gin.Context, err error, data interface{})

SuccessResponse ....

Types

type AsyncHostQuery added in v0.0.3

type AsyncHostQuery struct {
	IPRange string `form:"ip_range" json:"ip_range,omitempty" binding:"required"`
	TagId   int    `form:"tag_id" json:"tag_id"  binding:"required"`
}

type BatchPortQuery added in v0.0.3

type BatchPortQuery struct {
	Delay uint32      `form:"delay,default=0" json:"delay,omitempty"`
	Ports []PortQuery `form:"ports" json:"ports"`
}

type BatchServiceQuery added in v0.0.3

type BatchServiceQuery struct {
	Delay    uint32         `form:"delay,default=0" json:"delay,omitempty"`
	Services []ServiceQuery `form:"services" json:"services,omitempty"`
}

type BatchSettingQuery added in v0.0.3

type BatchSettingQuery struct {
	Delay uint32   `form:"delay,default=0" json:"delay,omitempty"`
	Hosts []string `form:"hosts" json:"hosts,omitempty" binding:"required"`
}

type BatchZoneQuery added in v0.0.3

type BatchZoneQuery struct {
	Delay        uint32    `form:"delay,default=0" json:"delay,omitempty"`
	ActionObject []ZoneDst `form:"action_object" json:"action_object,omitempty" binding:"required"`
}

type Err

type Err struct {
	Code    int
	Message string
	Err     error
}

Err represents an error

func (*Err) Error

func (err *Err) Error() string

type Errno

type Errno struct {
	Code    int
	Message string
}

Errno ...

func (Errno) Error

func (err Errno) Error() string

type ForwardQuery added in v0.0.3

type ForwardQuery struct {
	Ip      string            `form:"ip" json:"ip" binding:"required"`
	Zone    string            `form:"zone,default=public" json:"zone"`
	Timeout uint32            `form:"timeout,default=0" json:"timeout"`
	Forward *apis.ForwardPort `form:"forward" json:"forward,omitempty" binding:"required"`
}

type HostQuery added in v0.0.3

type HostQuery struct {
	IP       string `form:"ip" json:"ip,omitempty" binding:"required"`
	TagId    int    `form:"tag_id" json:"tag_id"  binding:"required"`
	Hostname string `form:"hostname" json:"hostname" `
	ID       int    `form:"id" json:"id" binding:"omitempty"`
	Limit    uint16 `form:"limit,default=100" json:"limit"`
	Offset   uint16 `form:"offset,default=0" json:"offset"`
}

type IDQuery added in v0.0.3

type IDQuery struct {
	ID uint64 `form:"id" json:"id,omitempty" binding:"required"`
}

type InfoQuery added in v0.0.3

type InfoQuery struct {
	Token string `form:"token" json:"token" binding:"required"`
}

type InfoResp added in v0.0.3

type InfoResp struct {
	Username string `form:"username" json:"username" binding:"required"`
	UserRole string `form:"role" json:"role" binding:"required"`
}

type ListHostQuery added in v0.0.3

type ListHostQuery struct {
	Limit  uint16 `form:"limit,default=100" json:"limit"`
	Offset uint16 `form:"offset,default=0" json:"offset"`
	Sort   string `form:"sort,default=desc" json:"sort"`
}

type ListQuery added in v0.0.3

type ListQuery struct {
	ID     int    `form:"id" json:"id"`
	Simple uint8  `form:"simple,omitempty,default=0" json:"simple"`
	Limit  uint16 `form:"limit,default=10" json:"limit"`
	Offset uint16 `form:"offset,default=0" json:"offset"`
	Sort   string `form:"sort,default=desc" json:"sort"`
}

type ListTagQuery added in v0.0.3

type ListTagQuery struct {
	ID     int    `form:"id" json:"id"`
	Limit  uint16 `form:"limit,default=50" json:"limit"`
	Offset uint16 `form:"offset,default=0" json:"offset"`
	Sort   string `form:"sort,default=desc" json:"sort"`
}

type PortEditQuery added in v0.0.3

type PortEditQuery struct {
	Port       uint16 `form:"port" json:"port" binding:"required"`
	Protocol   string `form:"protocol" json:"protocol" binding:"required"`
	TemplateId int    `form:"template_id" json:"template_id" binding:"required"`
	ID         uint64 `form:"id" json:"id,omitempty" binding:"omitempty"`
}

type PortQuery added in v0.0.3

type PortQuery struct {
	Ip      string    `form:"ip" json:"ip" binding:"required"`
	Zone    string    `form:"zone,default=public" json:"zone"`
	Timeout uint32    `form:"timeout,default=0" json:"timeout"`
	Port    apis.Port `form:"port" json:"port,omitempty" binding:"required"`
}

type Query added in v0.0.3

type Query struct {
	Ip      string            `form:"ip" json:"ip" binding:"required"`
	Zone    string            `form:"zone,default=public" json:"zone"`
	Timeout uint32            `form:"timeout,default=0" json:"timeout"`
	Port    *apis.Port        `form:"port" json:"port,omitempty"`
	Forward *apis.ForwardPort `form:"forward" json:"forward,omitempty"`
	Rich    *apis.Rule        `form:"rich" json:"rich,omitempty"`
	Service string            `form:"service" json:"service,omitempty"`
}

type RemoveQuery added in v0.0.3

type RemoveQuery struct {
	Ip   string `form:"ip" json:"ip" binding:"required"`
	Name string `form:"name" json:"name" binding:"required"`
}

type Response added in v0.0.3

type Response struct {
	Code int         `form:"code" json:"code,omitempty"`
	Msg  string      `form:"msg" json:"msg,omitempty"`
	Data interface{} `form:"data" json:"data,omitempty"`
}

type ResponseSlice added in v0.0.3

type ResponseSlice struct {
	Code int         `form:"code" json:"code,omitempty"`
	Msg  []string    `form:"msg" json:"msg,omitempty"`
	Data interface{} `form:"data" json:"data,omitempty"`
}

type RichEditQuery added in v0.0.3

type RichEditQuery struct {
	Family      string   `form:"family" json:"family,omitempty" binding:"omitempty"`
	Source      string   `form:"source" json:"source,omitempty" binding:"omitempty"`
	Destination string   `form:"destination" json:"destination,omitempty" binding:"omitempty"`
	Port        []string `form:"port" json:"port,omitempty" binding:"omitempty"`
	Protocol    string   `form:"protocol" json:"protocol,omitempty" binding:"omitempty"`
	Action      string   `form:"action" json:"action,omitempty" binding:"required"`
	Limit       uint16   `form:"limit" json:"limit,omitempty" binding:"omitempty"`
	LimitUnit   string   `form:"limit_unit" json:"limit_unit,omitempty" binding:"omitempty"`
	TemplateId  int      `form:"template_id" json:"template_id" binding:"required"`
	ID          uint64   `form:"id" json:"id,omitempty" binding:"omitempty"`
}

type RichQuery added in v0.0.3

type RichQuery struct {
	Ip      string     `form:"ip" json:"ip" binding:"required"`
	Zone    string     `form:"zone,default=public" json:"zone"`
	Timeout uint32     `form:"timeout,default=0" json:"timeout"`
	Rich    *apis.Rule `form:"rich" json:"rich,omitempty" binding:"required"`
}

type ServiceQuery added in v0.0.3

type ServiceQuery struct {
	Ip      string `form:"ip" json:"ip" binding:"required"`
	Zone    string `form:"zone,default=public" json:"zone"`
	Timeout uint32 `form:"timeout,default=0" json:"timeout"`
	Service string `form:"service" json:"service,omitempty" binding:"required"`
}

type ServiceSettingQuery added in v0.0.3

type ServiceSettingQuery struct {
	Host        string               `form:"host" json:"host" binding:"required"`
	ServiceName string               `form:"service_name" json:"service_name" binding:"required"`
	Setting     *apis.ServiceSetting `form:"setting" json:"setting,omitempty" binding:"required"`
}

type TagEditQuery added in v0.0.3

type TagEditQuery struct {
	Name        string `form:"name" json:"name,omitempty" binding:"required"`
	Description string `form:"description" json:"description"`
	ID          int    `form:"id" json:"id,omitempty" binding:"omitempty"`
}

type TemplateEditQuery added in v0.0.3

type TemplateEditQuery struct {
	Name        string `form:"name" json:"name,omitempty" binding:"required"`
	Description string `form:"description" json:"description"`
	Target      string `form:"target" json:"target"`
	ID          uint64 `form:"id" json:"id,omitempty" binding:"omitempty"`
}

type TokenEditQuery added in v0.0.3

type TokenEditQuery struct {
	Description string `json:"description,omitempty" binding:"omitempty"`
	SignedTo    string `json:"signed_to,omitempty" binding:"omitempty"`
	IsUpdate    bool   `json:"is_update,omitempty" binding:"omitempty"`
	ID          uint64 `form:"id" json:"id,omitempty" binding:"omitempty"`
}

type UserQuery added in v0.0.3

type UserQuery struct {
	Username string `form:"username" json:"username,omitempty" binding:"required"`
	Password string `form:"password" json:"password,omitempty" binding:"required"`
}

type UserResp added in v0.0.3

type UserResp struct {
	UserID   uint64 `form:"user_id" json:"user_id,omitempty" binding:"required"`
	Username string `form:"username" json:"username,omitempty" binding:"required"`
	Token    string `form:"token" json:"token,omitempty" binding:"required"`
	Name     string `form:"name" json:"name,omitempty" binding:"required"`
	LoginIP  string `form:"login_ip" json:"login_ip,omitempty"`
}

type ZoneDst added in v0.0.3

type ZoneDst struct {
	Host string `form:"host" json:"host,omitempty" binding:"required"`
	Zone string `form:"zone" json:"zone,omitempty" binding:"required"`
}

type ZoneSettingQuery added in v0.0.3

type ZoneSettingQuery struct {
	Ip      string              `form:"ip" json:"ip" binding:"required"`
	Setting *apis.QuerySettings `form:"setting" json:"Setting,omitempty" binding:"required"`
}

Jump to

Keyboard shortcuts

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