src

package
v3.0.1-0...-70a4a6c Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SUCCESS = "0000"
	ERROR   = "0001"
)
View Source
const (
	URL = "http://cmdp.yurencloud.com/v1"
)

Variables

View Source
var (
	// cmd
	VersionCommand = cli.Command{
		Name:    "version",
		Usage:   "show version",
		Aliases: []string{"v"},
		Action: func(ctx *cli.Context) {
			fmt.Println("cmdp version 3.0.0")
		},
	}
	SearchCommand = cli.Command{
		Name:    "search",
		Aliases: []string{"s"},
		Usage:   "search command, code, account, text, etc.",
		Action:  SearchAction,
		Flags: []cli.Flag{
			cli.IntFlag{
				Name:  "page,p",
				Usage: "set page number",
				Value: 1,
			},
			cli.IntFlag{
				Name:  "size,s",
				Usage: "set page size",
				Value: 20,
			},
			cli.BoolFlag{
				Name:  "all,a",
				Usage: "get all commands list",
			},
		},
	}
	CreateCmdCommand = cli.Command{
		Name:    "create",
		Aliases: []string{"c"},
		Usage:   "create command to remote",
		Action:  CreateCmdAction,
		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "public,p",
				Usage: "set public",
			},
		},
	}
	ForkCmdCommand = cli.Command{
		Name:    "forkcmd",
		Aliases: []string{"fc"},
		Usage:   "fork command, code, account, text, etc.",
		Action:  ForkCmdAction,
	}
	DeleteCmdCommand = cli.Command{
		Name:    "delete",
		Aliases: []string{"d"},
		Usage:   "delete command by id",
		Action:  DeleteCmdAction,
	}
	ExecCommand = cli.Command{
		Name:    "exec",
		Aliases: []string{"e"},
		Usage:   "exec command",
		Action:  ExecAction,
		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "file,f",
				Usage: "exec command from file",
			},
			cli.BoolFlag{
				Name:  "print,p",
				Usage: "not exec, only print command or file content",
			},
			cli.BoolFlag{
				Name:  "force,F",
				Usage: "force exec other user's dangerous command!",
			},
		},
	}
	// user
	RegisterCommand = cli.Command{
		Name:   "register",
		Usage:  "user register",
		Action: RegisterAction,
	}
	LoginCommand = cli.Command{
		Name:   "login",
		Usage:  "login by username and password",
		Action: LoginAction,
	}
	LogoutCommand = cli.Command{
		Name:   "logout",
		Usage:  "logout",
		Action: LogoutAction,
	}
	ResetPasswordCommand = cli.Command{
		Name:   "reset",
		Usage:  "reset password",
		Action: ResetPasswordAction,
	}
	UpdateInfoCommand = cli.Command{
		Name:   "info",
		Usage:  "update user introduction",
		Action: UpdateInfoAction,
	}

	// file
	PushFileCommand = cli.Command{
		Name:    "push",
		Aliases: []string{"p"},
		Usage:   "push your file to remote",
		Action:  PushFileAction,
		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "public,p",
				Usage: "set public",
			},
		},
	}
	ForkFileCommand = cli.Command{
		Name:    "forkfile",
		Aliases: []string{"ff"},
		Usage:   "fork file.",
		Action:  ForkFileAction,
	}
	PullFileCommand = cli.Command{
		Name:    "pull",
		Aliases: []string{"l", "pl", "P"},
		Usage:   "pull your file from remote",
		Action:  PullFileAction,
		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "print,p",
				Usage: "not download, only print file content",
			},
		},
	}
	FindFileCommand = cli.Command{
		Name:    "find",
		Aliases: []string{"f"},
		Usage:   "find your files from remote by keyword",
		Action:  FindFileAction,
		Flags: []cli.Flag{
			cli.IntFlag{
				Name:  "page,p",
				Usage: "set page number",
				Value: 1,
			},
			cli.IntFlag{
				Name:  "size,s",
				Usage: "set page size",
				Value: 20,
			},
			cli.BoolFlag{
				Name:  "all,a",
				Usage: "get all files list",
			},
		},
	}
	RemoveFileCommand = cli.Command{
		Name:    "remove",
		Aliases: []string{"r"},
		Usage:   "remove your remote file by id",
		Action:  RemoveFileAction,
	}
	// star
	StarCommand = cli.Command{
		Name:   "star",
		Usage:  "star other user",
		Action: StarAction,
		Flags: []cli.Flag{
			cli.IntFlag{
				Name:  "page,p",
				Usage: "set page number",
				Value: 1,
			},
			cli.IntFlag{
				Name:  "size,s",
				Usage: "set page size",
				Value: 20,
			},
			cli.IntFlag{
				Name:  "delete,d",
				Usage: "delete a star",
				Value: 0,
			},
			cli.StringFlag{
				Name:  "keyword,k",
				Usage: "search star by keyword",
				Value: "",
			},
		},
	}
	UpdateCommand = cli.Command{
		Name:   "update",
		Usage:  "update cmdp version",
		Action: UpdateAction,
	}
	UserCommand = cli.Command{
		Name:    "user",
		Aliases: []string{"u"},
		Usage:   "search users, order by stars count desc, cmds count desc, files count desc",
		Action:  UserAction,
		Flags: []cli.Flag{
			cli.IntFlag{
				Name:  "page,p",
				Usage: "set page number",
				Value: 1,
			},
			cli.IntFlag{
				Name:  "size,s",
				Usage: "set page size",
				Value: 20,
			},
			cli.BoolFlag{
				Name:  "all,a",
				Usage: "get all users list",
			},
			cli.BoolFlag{
				Name:  "official,o",
				Usage: "get all official account list",
			},
		},
	}
)

Functions

func CreateCmdAction

func CreateCmdAction(ctx *cli.Context)

func CreateToken

func CreateToken(token interface{})

func DeleteCmdAction

func DeleteCmdAction(ctx *cli.Context)

func Exec

func Exec(s string) (string, error)

func ExecAction

func ExecAction(ctx *cli.Context)

func FindFileAction

func FindFileAction(ctx *cli.Context)

func ForkCmdAction

func ForkCmdAction(ctx *cli.Context)

func ForkFileAction

func ForkFileAction(ctx *cli.Context)

func Http

func Http(method string, path string, param string) []byte

func HttpJson

func HttpJson(method string, path string, param []byte) []byte

func LoginAction

func LoginAction(ctx *cli.Context)

func LogoutAction

func LogoutAction(ctx *cli.Context)

func PathExists

func PathExists(path string) (bool, error)

func PullFileAction

func PullFileAction(ctx *cli.Context)

func PushFileAction

func PushFileAction(ctx *cli.Context)

func ReadToken

func ReadToken() ([]byte, error)

func RegisterAction

func RegisterAction(ctx *cli.Context)

func RemoveFileAction

func RemoveFileAction(ctx *cli.Context)

func ResetPasswordAction

func ResetPasswordAction(ctx *cli.Context)

func SearchAction

func SearchAction(ctx *cli.Context)

cmd

func StarAction

func StarAction(ctx *cli.Context)

func UpdateAction

func UpdateAction(ctx *cli.Context)

func UpdateInfoAction

func UpdateInfoAction(ctx *cli.Context)

func UserAction

func UserAction(ctx *cli.Context)

Types

type Cmd

type Cmd struct {
	Id        int
	UserId    int
	Cmd       string
	Keyword   string
	Comment   string
	Private   bool
	CreatedAt time.Time
	UpdatedAt time.Time
}

所有命令,代码 都保存在这个表中

type CmdRespond

type CmdRespond struct {
	Status  string
	Message string
	Data    Cmd
}

func GetCmd

func GetCmd(keyword string) CmdRespond

type CmdsRespond

type CmdsRespond struct {
	Status  string
	Message string
	Data    []Cmd
}

func DeleteStar

func DeleteStar(id int) CmdsRespond
func Search(keyword string, page int, size int) CmdsRespond

type File

type File struct {
	Id        int
	UserId    int
	Name      string // file name
	Content   string // you can save txt,json,markdown,sh... here
	Comment   string // comment for Cmd
	Keyword   string // keyword for Cmd
	Private   bool   // is private cmd, default false
	CreatedAt time.Time
	UpdatedAt time.Time
}

type FilesDownloadRespond

type FilesDownloadRespond struct {
	Status  string
	Message string
	Data    File
}

func DownloadFile

func DownloadFile(keyword string) FilesDownloadRespond

type FilesRespond

type FilesRespond struct {
	Status  string
	Message string
	Data    []File
}

func SearchFile

func SearchFile(keyword string, page int, size int) FilesRespond

type Respond

type Respond struct {
	Status  string
	Message string
	Data    interface{}
}

func Create

func Create(cmd Cmd) Respond

func CreateFile

func CreateFile(file *File) Respond

func CreateStar

func CreateStar(username string) Respond

func Delete

func Delete(id string) Respond

func DeleteFile

func DeleteFile(id string) Respond

func ForkCmd

func ForkCmd(keyword string) Respond

func ForkFile

func ForkFile(keyword string) Respond

func Login

func Login(username string, password string) Respond

func Register

func Register(username string, password string) Respond

func ResetPassword

func ResetPassword(password string) Respond

func UpdateInfo

func UpdateInfo(info string) Respond

type StarUser

type StarUser struct {
	StarId    int
	UserId    int
	Username  string    `orm:"size(255)"`
	CreatedAt time.Time `orm:"auto_now_add;type(datetime)"`
	CmdCount  int
	StarCount int
	FileCount int
	User      User
}

type StarsRespond

type StarsRespond struct {
	Status  string
	Message string
	Data    []StarUser
}

func SearchStar

func SearchStar(page int, size int, keyword string) StarsRespond

type User

type User struct {
	Id        int
	Username  string
	Info      string
	Official  bool
	CreatedAt time.Time
}

type UserResult

type UserResult struct {
	Username  string
	Info      string
	CreatedAt time.Time
	CmdCount  int
	FileCount int
	StarCount int
}

type UsersRespond

type UsersRespond struct {
	Status  string
	Message string
	Data    []UserResult
}

func SearchUser

func SearchUser(page int, size int, keyword string, official string) UsersRespond

Jump to

Keyboard shortcuts

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