utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_COUNT       = 10000
	MAX_SIZE        = 1 * 1024 * 1024 * 1024
	MAX_PATH_LENGTH = 512
)

Variables

This section is empty.

Functions

func DBOrder

func DBOrder(orders []Order, validOrderMap map[string]string) string

func DeleteStrSliceElms

func DeleteStrSliceElms(sl []string, elms ...string) []string

func EnsureIndex

func EnsureIndex(ctx context.Context, collection *mongo.Collection, indexName string, unique bool, index primitive.D) (err error)

func GenClusterID

func GenClusterID() string

GenClusterID ...

func GenDataModelEntitySetName

func GenDataModelEntitySetName(name string) string

GenDataModelEntitySetName ...

func GenDataModelHeaderOfID

func GenDataModelHeaderOfID(name string) string

GenDataModelHeaderOfID ...

func GenDataModelID

func GenDataModelID() string

GenDataModelID ...

func GenNotebookServerID

func GenNotebookServerID() string

GenNotebookServerID ...

func GenPublicWorkspaceID

func GenPublicWorkspaceID() string

GenPublicWorkspaceID ...

func GenRunID

func GenRunID() string

GenRunID ...

func GenSubmissionID

func GenSubmissionID() string

GenSubmissionID ...

func GenWorkflowFileID

func GenWorkflowFileID() string

GenWorkflowFileID ...

func GenWorkflowID

func GenWorkflowID() string

GenWorkflowID ...

func GenWorkflowVersionID

func GenWorkflowVersionID() string

GenWorkflowVersionID ...

func GenWorkspaceID

func GenWorkspaceID() string

GenWorkspaceID ...

func GetDataModelType

func GetDataModelType(dataModelName string) string

GetDataModelType ...

func GetSubPath

func GetSubPath(basepath, targpath string) (string, bool)

GetSubPath check if target path is subpath of basepath and return subpath

func GrpcDial

func GrpcDial(conn ConnectInfo, authInfo AuthInfo) (*grpc.ClientConn, error)

GrpcDial create grpc client connection

func HttpDial

func HttpDial(conn ConnectInfo, authInfo AuthInfo) (*c.Client, error)

HttpDial create grpc client connection

func In

func In(elm string, elms []string) bool

In ...

func MarshalParamValue

func MarshalParamValue(value interface{}) (string, error)

MarshalParamValue ...

func NewBasicAuthRPCCredentials

func NewBasicAuthRPCCredentials(username, password string) credentials.PerRPCCredentials

NewBasicAuthRPCCredentials create rpc credentials with basic auth

func NewHTTPTlSConfig

func NewHTTPTlSConfig(conn ConnectInfo) (*tls.Config, error)

func NewRPCCredentialFromAuthInfo

func NewRPCCredentialFromAuthInfo(authInfo AuthInfo) credentials.PerRPCCredentials

func NewTokenRPCCredentials

func NewTokenRPCCredentials(token string) credentials.PerRPCCredentials

NewTokenRPCCredentials create rpc credentials with token

func PointBool

func PointBool(b bool) *bool

PointBool convert bool to point of bool.

func PointFloat64

func PointFloat64(f float64) *float64

PointFloat64 convert int64 to point of float64.

func PointInt32

func PointInt32(i int32) *int32

PointInt32 convert int32 to point of int32.

func PointInt64

func PointInt64(i int64) *int64

PointInt64 convert int64 to point of int64.

func PointMetav1Time

func PointMetav1Time(b metav1.Time) *metav1.Time

PointMetav1Time convert metav1.Time to point of metav1.Time.

func PointString

func PointString(s string) *string

PointString convert string to point of string.

func PointTime

func PointTime(b time.Time) *time.Time

PointTime convert time.Time to point of time.Time.

func ReadDataModelFromCSV

func ReadDataModelFromCSV(filePath string) ([]string, [][]string, error)

func SearchWordFilter

func SearchWordFilter(db *gorm.DB, word string, fields []string, exact bool) *gorm.DB

SearchWordFilter splits keyword by special characters, and the relation between keywords is 'OR'. In addition, we don't need to escape character because special characters has been removed as delimiters.

func ToGRPCError

func ToGRPCError(err error) error

ToGRPCError return grpc status error

func UnmarshalParamValue

func UnmarshalParamValue(value string) interface{}

UnmarshalParamValue ...

func Unzip

func Unzip(zipFilePath, targetDir string) error

func ValidateFSDirectory

func ValidateFSDirectory(dirname string) error

ValidateFSDirectory check specified path exist and is folder return os.ErrNotExist if not exist

func ValidateFileExist

func ValidateFileExist(filePath string) error

ValidateFileExist check if given file exist in path.

func WriteHertzAcceptedResponse

func WriteHertzAcceptedResponse(c *app.RequestContext)

WriteHertzAcceptedResponse for soft delete resource.

func WriteHertzCreatedResponse

func WriteHertzCreatedResponse(c *app.RequestContext, data interface{})

WriteHertzCreatedResponse for create resource.

func WriteHertzErrorResponse

func WriteHertzErrorResponse(c *app.RequestContext, err error)

WriteHertzErrorResponse for error response.

func WriteHertzOKResponse

func WriteHertzOKResponse(c *app.RequestContext, data interface{})

WriteHertzOKResponse for all success request.

func ZipDir

func ZipDir(srcDir string, zipFileName string) error

Types

type AuthInfo

type AuthInfo struct {
	// username
	Username string `json:"username,omitempty" mapstructure:"username,omitempty"`
	// password
	Password string `json:"password,omitempty" mapstructure:"password,omitempty"`
	// authorization token
	AuthToken string `json:"authToken,omitempty" mapstructure:"authToken,omitempty"`
}

func (AuthInfo) Validate

func (a AuthInfo) Validate() error

type ConnectInfo

type ConnectInfo struct {
	// server address
	ServerAddr string `json:"serverAddr" mapstructure:"serverAddr"`
	// server name to override
	ServerName string `json:"serverName,omitempty" mapstructure:"serverName,omitempty"`
	// whether use tls
	Insecure bool `json:"insecure,omitempty" mapstructure:"insecure,omitempty"`
	// server cert file
	ServerCertFile string `json:"serverCertFile,omitempty" mapstructure:"serverCertFile,omitempty"`
	// client cert file
	ClientCertFile string `json:"clientCertFile,omitempty" mapstructure:"clientCertFile,omitempty"`
	// client  key file
	ClientCertKeyFile string `json:"clientCertKeyFile" mapstructure:"clientCertKeyFile,omitempty"`
	// ca file
	CaFile string `json:"caFile" mapstructure:"caFile,omitempty"`
}

func (ConnectInfo) Validate

func (c ConnectInfo) Validate() error

type MongoPaginate

type MongoPaginate struct {
	// contains filtered or unexported fields
}

func NewMongoPaginate

func NewMongoPaginate(limit, page int) *MongoPaginate

func (*MongoPaginate) GetPaginatedOpts

func (mp *MongoPaginate) GetPaginatedOpts() *options.FindOptions

type Order

type Order struct {
	Field     string
	Ascending bool
}

Order ...

type Pagination

type Pagination struct {
	Size   int `validate:"gte=0,lte=100"`
	Page   int `validate:"gte=1"`
	Orders []Order
}

Pagination ...

func NewPagination

func NewPagination(size int, page int) *Pagination

NewPagination returns Pagination of size and page.

func (*Pagination) GetHasMore

func (q *Pagination) GetHasMore(totalCount int) bool

GetHasMore Get has more.

func (*Pagination) GetLimit

func (q *Pagination) GetLimit() int

GetLimit Get limit.

func (*Pagination) GetOffset

func (q *Pagination) GetOffset() int

GetOffset Get offset.

func (*Pagination) GetOrderBy

func (q *Pagination) GetOrderBy() string

GetOrderBy Get orderBy string.

func (*Pagination) GetPage

func (q *Pagination) GetPage() int

GetPage Get OrderBy.

func (*Pagination) GetQueryString

func (q *Pagination) GetQueryString() string

GetQueryString get query string.

func (*Pagination) GetSize

func (q *Pagination) GetSize() int

GetSize Get OrderBy.

func (*Pagination) GetTotalPages

func (q *Pagination) GetTotalPages(totalCount int) int

GetTotalPages Get total pages int.

func (*Pagination) SetOrderBy

func (q *Pagination) SetOrderBy(orderByQuery string) error

SetOrderBy Set order by.

type TransportWithAuth

type TransportWithAuth struct {
	*http.Transport
	// contains filtered or unexported fields
}

func NewTransportWithAuth

func NewTransportWithAuth(conn ConnectInfo, authInfo AuthInfo) (*TransportWithAuth, error)

func (TransportWithAuth) Client

func (t TransportWithAuth) Client() *http.Client

func (TransportWithAuth) GetRequestMetadata

func (b TransportWithAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error)

func (TransportWithAuth) RequireTransportSecurity

func (b TransportWithAuth) RequireTransportSecurity() bool

func (TransportWithAuth) RoundTrip

func (t TransportWithAuth) RoundTrip(req *http.Request) (*http.Response, error)

Directories

Path Synopsis
Package bom nolint
Package bom nolint

Jump to

Keyboard shortcuts

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