common

package
v0.0.0-...-6de39a6 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VENDOR_SEP    = ";"
	REMOTE_PREFIX = "remote:"
)

Variables

This section is empty.

Functions

func Atoi

func Atoi(s string) (int64, error)

func EscapeText

func EscapeText(parseMode string, text string) string

func Itoa

func Itoa(i int64) string

func NextRandom

func NextRandom() string

func Respond

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

func Uint32

func Uint32() uint32

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 ArchiveChat

type ArchiveChat struct {
	Vendor string `yaml:"vendor"`
	UID    string `yaml:"uid"`
	ChatID int64  `yaml:"chat_id"`
}

type BlobData

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

type Chat

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

type Configure

type Configure struct {
	Master struct {
		APIURL    string        `yaml:"api_url"`
		LocalMode bool          `yaml:"local_mode"`
		AdminID   int64         `yaml:"admin_id"`
		Token     string        `yaml:"token"`
		Proxy     string        `yaml:"proxy"`
		PageSize  int           `yaml:"page_size"`
		Archive   []ArchiveChat `yaml:"archive"`

		Telegraph struct {
			Enable bool     `ymal:"enable"`
			Proxy  string   `yaml:"proxy"`
			Tokens []string `yaml:"tokens"`
		} `yaml:"telegraph"`
	} `yaml:"master"`

	Service struct {
		Addr        string        `yaml:"addr"`
		Secret      string        `yaml:"secret"`
		SendTiemout time.Duration `yaml:"send_timeout"`
	} `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 EventType

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

func (EventType) String

func (t EventType) String() string

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 Limb

type Limb struct {
	Type   string // Type: telegram, qq, wechat, etc
	UID    string
	ChatID string
}

func LimbFromString

func LimbFromString(str string) (*Limb, error)

func (Limb) String

func (l Limb) String() string

type LocationData

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

type MessageType

type MessageType int
const (
	MsgRequest MessageType = iota
	MsgResponse
)

func (MessageType) String

func (t MessageType) String() string

type OctopusEvent

type OctopusEvent struct {
	Vendor    Vendor     `json:"vendor,omitempty"`
	ID        string     `json:"id,omitempty"`
	ThreadID  string     `json:"thread_id,omitempty"`
	Timestamp int64      `json:"timestamp,omitempty"`
	From      User       `json:"from,omitempty"`
	Chat      Chat       `json:"chat,omitempty"`
	Type      EventType  `json:"type,omitempty"`
	Content   string     `json:"content,omitempty"`
	Reply     *ReplyInfo `json:"reply,omitempty"`
	Data      any        `json:"data,omitempty"`

	Callback func(*OctopusEvent, error) `json:"-"`
}

func (*OctopusEvent) UnmarshalJSON

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

type OctopusMessage

type OctopusMessage struct {
	ID   int64       `json:"id,omitempty"`
	Type MessageType `json:"type,omitempty"`
	Data any         `json:"data,omitempty"`
}

func (*OctopusMessage) UnmarshalJSON

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

type OctopusRequest

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

func (*OctopusRequest) UnmarshalJSON

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

type OctopusResponse

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

func (*OctopusResponse) UnmarshalJSON

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

type ReplyInfo

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

type RequestType

type RequestType int
const (
	ReqDisconnect RequestType = iota
	ReqPing
	ReqEvent
)

func (RequestType) String

func (t RequestType) String() string

type ResponseType

type ResponseType int
const (
	RespClosed ResponseType = iota
	RespPing
	RespEvent
)

func (ResponseType) String

func (t ResponseType) String() string

type User

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

type Vendor

type Vendor struct {
	Type string `json:"type,omitempty"`
	UID  string `json:"uid,omitempty"`
}

func VendorFromString

func VendorFromString(str string) (*Vendor, error)

func (Vendor) String

func (v Vendor) String() string

Jump to

Keyboard shortcuts

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