common

package
v0.0.0-...-2d28aed Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Respond

func Respond(w http.ResponseWriter, data any) error

Types

type AppData

type AppData struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"desc,omitempty"`
	Source      string `json:"source,omitempty"`
	URL         string `json:"url,omitempty"`

	Content string               `json:"raw,omitempty"`
	Blobs   map[string]*BlobData `json:"blobs,omitempty"`
}

type BlobData

type BlobData struct {
	Name   string `json:"name,omitempty"`
	Mime   string `json:"mime,omitempty"`
	Binary []byte `json:"binary"`
}

type Chat

type Chat struct {
	ID    string   `json:"id"`
	Type  ChatType `json:"type"`
	Title string   `json:"title,omitempty"`
}

type ChatType

type ChatType int
const (
	ChatPrivate ChatType = iota
	ChatGroup
)

func (ChatType) String

func (t ChatType) String() string

type Configure

type Configure struct {
	Wechat struct {
		Version        string        `yaml:"version"`
		ListenPort     int32         `yaml:"listen_port"`
		InitTimeout    time.Duration `yaml:"init_timeout"`
		RequestTimeout time.Duration `yaml:"request_timeout"`
		Workdir        string        `yaml:"-"`
	} `yaml:"wechat"`

	Service struct {
		Addr         string        `yaml:"addr"`
		Secret       string        `yaml:"secret"`
		PingInterval time.Duration `yaml:"ping_interval"`
	} `yaml:"service"`

	Log struct {
		Level string `yaml:"level"`
	} `yaml:"log"`
}

func LoadConfig

func LoadConfig(path string) (*Configure, error)

type ErrorResponse

type ErrorResponse struct {
	HTTPStatus int    `json:"-"`
	Code       string `json:"code"`
	Message    string `json:"message"`
}

func (*ErrorResponse) Error

func (er *ErrorResponse) Error() string

func (ErrorResponse) Write

func (er ErrorResponse) Write(w http.ResponseWriter)

type Event

type Event struct {
	ID        string     `json:"id"`
	ThreadID  string     `json:"thread_id,omitempty"`
	Timestamp int64      `json:"timestamp"`
	From      User       `json:"from"`
	Chat      Chat       `json:"chat"`
	Type      EventType  `json:"type"`
	Content   string     `json:"content,omitempty"`
	Mentions  []string   `json:"mentions,omitempty"`
	Reply     *ReplyInfo `json:"reply,omitempty"`
	Data      any        `json:"data,omitempty"`
}

func (*Event) UnmarshalJSON

func (o *Event) UnmarshalJSON(data []byte) error

type EventType

type EventType int
const (
	EventText EventType = iota
	EventPhoto
	EventSticker
	EventAudio
	EventVideo
	EventFile
	EventLocation
	EventNotice
	EventApp
	EventRevoke
	EventVoIP
	EventSystem
)

func (EventType) String

func (t EventType) String() string

type GroupInfo

type GroupInfo struct {
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Avatar  string   `json:"avatar,omitempty"`
	Notice  string   `json:"notice,omitempty"`
	Members []string `json:"members"`
}

type KeyMutex

type KeyMutex interface {
	// Acquires a lock associated with the specified ID, creates the lock if one doesn't already exist.
	LockKey(id string)

	// Releases the lock associated with the specified ID.
	// Returns an error if the specified ID doesn't exist.
	UnlockKey(id string) error
}

KeyMutex is a thread-safe interface for acquiring locks on arbitrary strings.

func NewHashed

func NewHashed(n int) KeyMutex

NewHashed returns a new instance of KeyMutex which hashes arbitrary keys to a fixed set of locks. `n` specifies number of locks, if n <= 0, we use number of cpus. Note that because it uses fixed set of locks, different keys may share same lock, so it's possible to wait on same lock.

type LocationData

type LocationData struct {
	Name      string  `json:"name,omitempty"`
	Address   string  `json:"address,omitempty"`
	Longitude float64 `json:"longitude"`
	Latitude  float64 `json:"latitude"`
}

type Message

type Message struct {
	ID   int64       `json:"id"`
	MXID string      `json:"mxid"`
	Type MessageType `json:"type"`
	Data any         `json:"data,omitempty"`
}

func (*Message) UnmarshalJSON

func (o *Message) UnmarshalJSON(data []byte) error

type MessageType

type MessageType int
const (
	MsgRequest MessageType = iota
	MsgResponse
)

func (MessageType) String

func (t MessageType) String() string

type ReplyInfo

type ReplyInfo struct {
	ID        string `json:"id"`
	Timestamp int64  `json:"ts"`
	Sender    string `json:"sender"`
	Content   string `json:"content"`
}

type Request

type Request struct {
	Type RequestType `json:"type"`
	Data any         `json:"data,omitempty"`
}

func (*Request) UnmarshalJSON

func (o *Request) UnmarshalJSON(data []byte) error

type RequestType

type RequestType int
const (
	ReqEvent RequestType = iota
	ReqConnect
	ReqDisconnect
	ReqLoginQR
	ReqIsLogin
	ReqGetSelf
	ReqGetUserInfo
	ReqGetGroupInfo
	ReqGetGroupMembers
	ReqGetGroupMemberNickname
	ReqGetFriendList
	ReqGetGroupList
)

func (RequestType) String

func (t RequestType) String() string

type Response

type Response struct {
	Type  ResponseType   `json:"type"`
	Error *ErrorResponse `json:"error,omitempty"`
	Data  any            `json:"data,omitempty"`
}

func (*Response) UnmarshalJSON

func (o *Response) UnmarshalJSON(data []byte) error

type ResponseType

type ResponseType int
const (
	RespEvent ResponseType = iota
	RespConnect
	RespDisconnect
	RespLoginQR
	RespIsLogin
	RespGetSelf
	RespGetUserInfo
	RespGetGroupInfo
	RespGetGroupMembers
	RespGetGroupMemberNickname
	RespGetFriendList
	RespGetGroupList
)

func (ResponseType) String

func (t ResponseType) String() string

type User

type User struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Remark   string `json:"remark,omitempty"`
}

type UserInfo

type UserInfo struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Avatar string `json:"avatar,omitempty"`
	Remark string `json:"remark,omitempty"`
}

Jump to

Keyboard shortcuts

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