common

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMessage

func ErrorMessage(err error) string

ErrorMessage unwraps an application error and returns its message. Non-application errors always return "Internal error".

func FindString

func FindString(strings []string, search string) int

FindString returns the search index of sorted strings.

func HasPrefixes

func HasPrefixes(src string, prefixes ...string) bool

HasPrefixes returns true if the string s has any of the given prefixes.

func RandomString

func RandomString(n int) string

RandomString returns a random string with length n.

Types

type Code

type Code int

Code is the error code.

const (
	// 0 ~ 99 general error
	Ok             Code = 0
	Internal       Code = 1
	NotAuthorized  Code = 2
	Invalid        Code = 3
	NotFound       Code = 4
	Conflict       Code = 5
	NotImplemented Code = 6

	// 101 ~ 199 db error
	DbConnectionFailure    Code = 101
	DbStatementSyntaxError Code = 102
	DbExecutionError       Code = 103

	// 201 db migration error
	// Db migration is a core feature, so we separate it from the db error
	MigrationSchemaMissing   Code = 201
	MigrationAlreadyApplied  Code = 202
	MigrationOutOfOrder      Code = 203
	MigrationBaselineMissing Code = 204
	MigrationPending         Code = 205
	MigrationFailed          Code = 206

	// 301 task error
	TaskTimingNotAllowed Code = 301

	// 10001 advisor error code
	CompatibilityDropDatabase  Code = 10001
	CompatibilityRenameTable   Code = 10002
	CompatibilityDropTable     Code = 10003
	CompatibilityRenameColumn  Code = 10004
	CompatibilityDropColumn    Code = 10005
	CompatibilityAddPrimaryKey Code = 10006
	CompatibilityAddUniqueKey  Code = 10007
	CompatibilityAddForeignKey Code = 10008
	CompatibilityAddCheck      Code = 10009
	CompatibilityAlterCheck    Code = 10010
	CompatibilityAlterColumn   Code = 10011
)

Application error codes.

func ErrorCode

func ErrorCode(err error) Code

ErrorCode unwraps an application error and returns its code. Non-application errors always return EINTERNAL.

type Error

type Error struct {
	// Machine-readable error code.
	Code Code

	// Embedded error.
	Err error
}

Error represents an application-specific error. Application errors can be unwrapped by the caller to extract out the code & message.

Any non-application error (such as a disk error) should be reported as an Internal error and the human user should only see "Internal error" as the message. These low-level internal error details should only be logged and reported to the operator of the application (not the end user).

func Errorf

func Errorf(code Code, err error) *Error

Errorf is a helper function to return an Error with a given code and error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface. Not used by the application otherwise.

type OauthContext

type OauthContext struct {
	ClientID     string
	ClientSecret string
	AccessToken  string
	RefreshToken string
	Refresher    TokenRefresher
}

OauthContext encapsulated the oauth info

type ProjectRole

type ProjectRole string

ProjectRole is the role in projects.

const (
	// ProjectOwner is the owner of a project.
	ProjectOwner ProjectRole = "OWNER"
	// ProjectDeveloper is the developer of a project.
	ProjectDeveloper ProjectRole = "DEVELOPER"
)

func (ProjectRole) String

func (e ProjectRole) String() string

type TokenRefresher

type TokenRefresher func(token, refreshToken string, expiresTs int64) error

TokenRefresher is a function refreshes the oauth token and updates the repository.

Jump to

Keyboard shortcuts

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