pkg

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextBlack = iota + 30
	TextRed
	TextGreen
	TextYellow
	TextBlue
	TextMagenta
	TextCyan
	TextWhite
)

Variables

View Source
var TemplateIgnore = ".templateignore"
View Source
var TemplateParseIgnore = ".templateparseignore"
View Source
var Version string

Version is the version of the binary

Functions

func Black

func Black(msg string) string

func Blue

func Blue(msg string) string

func CommitAndPushGithubRepo

func CommitAndPushGithubRepo(directory, branch, path, accessToken string, auth *http.BasicAuth) error

CommitAndPushGithubRepo commit and push github repo

func CopyDir

func CopyDir(srcPath string, destPath string) error

func CreateGithubRepo

func CreateGithubRepo(organization, name, description, token string, private bool) (*github.Repository, error)

CreateGithubRepo create github repo

func Cyan

func Cyan(msg string) string

func FileCopy

func FileCopy(src, dst string) (int64, error)

FileCopy copy file

func FileCreate

func FileCreate(content bytes.Buffer, name string) error

FileCreate create file

func FileMonitoringById

func FileMonitoringById(ctx context.Context, filePth string, id string, group string, hook func(context.Context, string, string, []byte))

func FileOpen

func FileOpen(content bytes.Buffer, name string, mode os.FileMode) error

func Generate

func Generate(c *TemplateConfig) (err error)

Generate example

func Generate(url, destinationPath string, cfg interface{}, githubConfig *GithubConfig, accessToken string) error {
	templatePath := filepath.Base(url)

func GetAppPath

func GetAppPath() string

GetAppPath Get the absolute path to the running directory

func GetCurrentPath

func GetCurrentPath() string

GetCurrentPath 获取当前路径,比如:E:/abc/data/test

func GetFileSize

func GetFileSize(filename string) int64

GetFileSize 获取文件大小

func GetGithubRepoAllBranches

func GetGithubRepoAllBranches(ctx context.Context, organization, name, token string) ([]*github.Branch, error)

GetGithubRepoAllBranches get all branches of github repo

func GetInstallPath

func GetInstallPath() string

GetInstallPath Different systems get different installation paths

func GetLatestVersion

func GetLatestVersion() string

GetLatestVersion get generate-tool version

func GetOrganizationsFromGithub

func GetOrganizationsFromGithub(ctx context.Context,
	conf *oauth2.Config,
	accessToken string) ([]string, error)

func GetParseFromTemplate

func GetParseFromTemplate(dir, subPath string) (map[string]string, error)

GetParseFromTemplate get parse keys from template

func GetSubPath

func GetSubPath(directory string) ([]string, error)

GetSubPath get directory's subject path

func GetTmpPath

func GetTmpPath() string

GetTmpPath interface pid file path

func GistClone

func GistClone(id, dir, accessToken string) error

GistClone clone gist repo

func GitClone

func GitClone(url, branch, directory string, noCheckout bool, accessToken string) (*git.Repository, error)

GitClone clone git repo

func GitCloneSSH

func GitCloneSSH(url, directory, reference, privateKeyFile, password string) error

GitCloneSSH clone git repo from ssh

func GitRemote

func GitRemote(url, directory string) error

GitRemote from remote git

func Green

func Green(msg string) string

func InArray

func InArray(vals []string, array []string, replace string, n int) bool

InArray 判断字符串是否在数组中

func IsWindows

func IsWindows() bool

IsWindows Determine whether the current system is a Windows system?

func Magenta

func Magenta(msg string) string

func NowEndDay

func NowEndDay() time.Time

func NowFormatDay

func NowFormatDay() string

func NowFormatHour

func NowFormatHour() string

func NowFormatMinute

func NowFormatMinute() string

func NowFormatMonth

func NowFormatMonth() string

func NowFormatSecond

func NowFormatSecond() string

func NowFormatYear

func NowFormatYear() string

func NowStartDay

func NowStartDay() time.Time

func PathCreate

func PathCreate(dir string) error

PathCreate create path

func PathExist

func PathExist(addr string) bool

PathExist path exist

func Pluralize

func Pluralize(word string) string

func Red

func Red(msg string) string

func SetColor

func SetColor(msg string, conf, bg, text int) string

func SimpleID

func SimpleID() string

SimpleID simple id

func TimeEndDay

func TimeEndDay(t time.Time) time.Time

func TimeFormatDay

func TimeFormatDay(t time.Time) string

func TimeFormatHour

func TimeFormatHour(t time.Time) string

func TimeFormatMinute

func TimeFormatMinute(t time.Time) string

func TimeFormatMonth

func TimeFormatMonth(t time.Time) string

func TimeFormatSecond

func TimeFormatSecond(t time.Time) string

func TimeFormatYear

func TimeFormatYear(t time.Time) string

func TimeStartDay

func TimeStartDay(t time.Time) time.Time

func White

func White(msg string) string

func Yellow

func Yellow(msg string) string

Types

type AccessType

type AccessType string
const (
	// DirectoryAccessType 目录类型
	DirectoryAccessType AccessType = "DIRECTORY"
	// MenuAccessType 菜单类型
	MenuAccessType AccessType = "MENU"
	// APIAccessType API类型
	APIAccessType AccessType = "API"
	// ComponentAccessType 组件类型
	ComponentAccessType AccessType = "COMPONENT"
)

func (AccessType) String

func (a AccessType) String() string

type BaseRule

type BaseRule struct {
	ID              string   `json:"id"`
	WarningOnly     bool     `json:"warningOnly,omitempty"`
	Len             uint8    `json:"len,omitempty"`
	Max             uint8    `json:"max,omitempty"`
	Min             uint8    `json:"min,omitempty"`
	Message         string   `json:"message,omitempty"`
	Pattern         string   `json:"pattern,omitempty"`
	Required        bool     `json:"required,omitempty"`
	Type            RuleType `json:"type,omitempty"`
	Whitespace      bool     `json:"whitespace,omitempty"`
	ValidateTrigger string   `json:"validateTrigger,omitempty"`
}

type Generator

type Generator struct {
	SubPath                  string
	TemplatePath             string
	DestinationPath          string
	Cfg                      interface{}
	TemplateIgnoreDirs       []string
	TemplateIgnoreFiles      []string
	TemplateParseIgnoreDirs  []string
	TemplateParseIgnoreFiles []string
}

Generator generate operator

func (*Generator) Traverse

func (e *Generator) Traverse() error

Traverse traverse all dir

func (*Generator) TraverseFunc

func (e *Generator) TraverseFunc(path string, f os.DirEntry, err error) error

TraverseFunc traverse callback

type GithubConfig

type GithubConfig struct {
	Name         string            `yaml:"name"`
	Organization string            `yaml:"organization"`
	Description  string            `yaml:"description"`
	Secrets      map[string]string `yaml:"secrets"`
	Token        string            `yaml:"token"`
}

type GithubOrganization

type GithubOrganization struct {
	Login            string `json:"login"`
	ID               int64  `json:"id"`
	NodeID           string `json:"node_id"`
	URL              string `json:"url"`
	ReposURL         string `json:"repos_url"`
	EventsURL        string `json:"events_url"`
	HooksURL         string `json:"hooks_url"`
	IssuesURL        string `json:"issues_url"`
	MembersURL       string `json:"members_url"`
	PublicMembersURL string `json:"public_members_url"`
	AvatarURL        string `json:"avatar_url"`
	Description      string `json:"description"`
}

type GithubUser

type GithubUser struct {
	Login             string `json:"login"`
	ID                int64  `json:"id"`
	NodeID            string `json:"node_id"`
	AvatarURL         string `json:"avatar_url"`
	GravatarID        string `json:"gravatar_id"`
	URL               string `json:"url"`
	HTMLURL           string `json:"html_url"`
	FollowersURL      string `json:"followers_url"`
	FollowingURL      string `json:"following_url"`
	GistsURL          string `json:"gists_url"`
	StarredURL        string `json:"starred_url"`
	SubscriptionsURL  string `json:"subscriptions_url"`
	OrganizationsURL  string `json:"organizations_url"`
	ReposURL          string `json:"repos_url"`
	EventsURL         string `json:"events_url"`
	ReceivedEventsURL string `json:"received_events_url"`
	Type              string `json:"type"`
	SiteAdmin         bool   `json:"site_admin"`
	Name              string `json:"name"`
	Company           string `json:"company"`
	Blog              string `json:"blog"`
	Location          string `json:"location"`
	Email             string `json:"email"`
	Hireable          bool   `json:"hireable"`
	Bio               string `json:"bio"`
	TwitterUsername   string `json:"twitter_username"`
	PublicRepos       int64  `json:"public_repos"`
	PublicGists       int64  `json:"public_gists"`
	Followers         int64  `json:"followers"`
	Following         int64  `json:"following"`
	CreatedAt         string `json:"created_at"`
	UpdatedAt         string `json:"updated_at"`
	PrivateGists      int64  `json:"private_gists"`
	TotalPrivateRepos int64  `json:"total_private_repos"`
	OwnedPrivateRepos int64  `json:"owned_private_repos"`
	DiskUsage         int64  `json:"disk_usage"`
	Collaborators     int64  `json:"collaborators"`
	TwoFactorAuth     bool   `json:"two_factor_authentication"`
	Plan              struct {
		Name          string `json:"name"`
		Space         int64  `json:"space"`
		Collaborators int64  `json:"collaborators"`
		PrivateRepos  int64  `json:"private_repos"`
	} `json:"plan"`
}

func GetUserFromGithub

func GetUserFromGithub(ctx context.Context, conf *oauth2.Config, accessToken string) (*GithubUser, error)

type OAuth2Provider added in v0.3.0

type OAuth2Provider string
const (
	// OAuth2GithubProvider github oauth provider
	OAuth2GithubProvider OAuth2Provider = "github"
	// OAuth2LarkProvider lark oauth provider
	OAuth2LarkProvider OAuth2Provider = "lark"
)

func (OAuth2Provider) String added in v0.3.0

func (o OAuth2Provider) String() string

type ReplaceHelper

type ReplaceHelper struct {
	// Root path
	Root string
	// OldText need to replace text
	OldText string
	// NewText new text
	NewText string
}

func (*ReplaceHelper) DoWork

func (h *ReplaceHelper) DoWork() error

type RuleType

type RuleType string
const (
	RUleTypeString RuleType = "string"
	RUleTypeNumber RuleType = "number"
	RUleTypeBool   RuleType = "boolean"
	RUleTypeMethod RuleType = "method"
	RUleTypeRegexp RuleType = "regexp"
	RUleTypeInt    RuleType = "integer"
	RUleTypeFloat  RuleType = "float"
	RUleTypeObject RuleType = "object"
	RUleTypeEnum   RuleType = "enum"
	RUleTypeDate   RuleType = "date"
	RUleTypeUrl    RuleType = "url"
	RUleTypeHex    RuleType = "hex"
	RUleTypeEmail  RuleType = "email"
)

type Task

type Task struct {
	ID       string
	Name     string
	Endpoint string
	Method   string
	Command  string
	Args     []string
	Body     io.Reader
	Python   string
	Writer   io.Writer
	Metadata map[string]string
	Timeout  time.Duration
}

func (*Task) Run

func (t *Task) Run() error

type TemplateConfig

type TemplateConfig struct {
	Service              string        `yaml:"service"`
	TemplateUrl          string        `yaml:"templateUrl"`
	TemplateLocal        string        `yaml:"templateLocal"`
	TemplateLocalSubPath string        `yaml:"templateLocalSubPath"`
	CreateRepo           bool          `yaml:"createRepo"`
	Destination          string        `yaml:"destination"`
	Github               *GithubConfig `yaml:"github"`
	Params               interface{}   `yaml:"params"`
	Ignore               []string      `yaml:"ignore"`
}

func (*TemplateConfig) OnChange

func (e *TemplateConfig) OnChange()

type TreeImp

type TreeImp interface {
	GetIndex() string
	GetParentID() string
	AddChildren([]TreeImp)
	SortChildren()
}

func BuildTree

func BuildTree(list []TreeImp, parentID string) []TreeImp

BuildTree 使用递归实现树

Jump to

Keyboard shortcuts

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