model

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiPrefix        = "api"
	ApiVersion       = "v0"
	ApiPublic        = "public"
	Api_Push         = "push"
	Api_Pull         = "pull"
	Api_History      = "history"
	Api_Upload       = "upload"
	Api_Download     = "download/*filename"
	Api_DownloadPure = "download"

	ApiPublicShare = "share"
)

Variables

View Source
var Version string = "v0.0.0"

Functions

func CheckConf

func CheckConf(conf *Conf)

func CmpClipboard

func CmpClipboard(a *Clipboard, b *Clipboard) bool

func GetMD5Hash

func GetMD5Hash(text string) string

func IndexClipboardArray

func IndexClipboardArray(arr []Clipboard, item *Clipboard) int

func InitFlags

func InitFlags(conf *Conf)

func InitLogger

func InitLogger(c *Conf)

func NewModuleLogger

func NewModuleLogger(module_name string) *logrus.Entry

func ParseTimeStr added in v0.3.0

func ParseTimeStr(t string) int64

return secs

func RandString

func RandString(size int) string

func TokenEncrypt

func TokenEncrypt(token string) string

func UrlDownloadApi

func UrlDownloadApi(c *Conf, fileName string) string

func UrlPullApi

func UrlPullApi(c *Conf) string

func UrlPushApi

func UrlPushApi(c *Conf) string

func UrlUploadApi

func UrlUploadApi(c *Conf) string

Types

type Clipboard

type Clipboard struct {
	Id          int64  `json:"-" db:"id"`
	Ts          int64  `json:"ts" db:"ts"` //ms timestamp
	Content     string `json:"content" db:"content"`
	Hostname    string `json:"hostname" db:"hostname"`         // sender
	ContentType string `json:"content_type" db:"content_type"` //
}

func NewClipoardWithDefault

func NewClipoardWithDefault() *Clipboard

func NewFullClipoard

func NewFullClipoard(c string) *Clipboard

It generates the hostname so take care of where it is called

type Conf

type Conf struct {
	Token  string `toml:"token"`
	Client struct {
		ServerUrl  string `toml:"server_url"`
		Connect    string `toml:"connect"`
		Adapter    string `toml:"adapter"`
		Interval   int    `toml:"interval"`
		Timeout    int64  `toml:"timeout"`
		XSelection string `toml:"X_selection"`
	} `toml:"client"`

	Server struct {
		DBPath                   string `toml:"db_path"`
		PullHistorySize          int    `toml:"pull_history_size"`
		TmpPath                  string `toml:"tmp_path"`
		DefaultFileLife          int64  `toml:"default_file_life"`
		TimerInterval            int    `toml:"timer_interval"`
		ClipboardHistoryPageSize int    `toml:"clipboard_history_page_size"`
		Port                     int    `toml:"port"`
		CacheMaxAge              int    `toml:"cache_max_age"`
	} `toml:"server"`
	// All struct should be read-only except runtime after LoadConf
	Runtime struct {
		Mode                  string
		ConfPath              string
		LogLevel              string
		PushMsg               string
		Download              string
		Upload                string
		Pull                  bool
		Latest                bool
		Test                  string
		TokenEncrypt          string
		ShowVersion           bool
		LogPath               string
		ShowHelp              bool
		UploadFileLifetime    int64
		UploadFileLifetimeStr string
	}
}

func FormatConf

func FormatConf(conf *Conf) *Conf

func LoadConf

func LoadConf(conf *Conf) *Conf

func NewConfWithDefault

func NewConfWithDefault() *Conf

Why go-toml? because gin need it! Default tag is not supported by go-toml now,so I have to implement this

type FileMetadata

type FileMetadata struct {
	Id        int64  `json:"-" db:"id"`
	CreatedTs int64  `json:"created_ts" db:"created_ts"` //ms timestamp
	ExpireTs  int64  `json:"expire_ts" db:"expire_ts"`   //ms timestamp
	FileName  string `json:"file_name" db:"file_name"`
	TmpPath   string `json:"tmp_path" db:"tmp_path"` //relative path based on the tmpPath in conf
}

func NewFileMetadataWithDefault

func NewFileMetadataWithDefault() *FileMetadata

type ServerResponse

type ServerResponse struct {
	Msg  string          `json:"msg"`
	Data json.RawMessage `json:"data"`
}

func NewDefaultServeRes

func NewDefaultServeRes(msg string, data []byte) *ServerResponse

Jump to

Keyboard shortcuts

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