utils

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2022 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckEmptyString

func CheckEmptyString(text string) (*string, error)

CheckEmptyString check that the string isn't empty

func CheckIdentifierExists

func CheckIdentifierExists(profile *profileutils.UserProfile, UID string) bool

CheckIdentifierExists check if an identifier exists

func CheckUserHasPermission added in v0.0.2

func CheckUserHasPermission(roles []profileutils.Role, permission profileutils.Permission) bool

CheckUserHasPermission takes in the user roles and a permission and verifies that the user has required permissions

func FindItem

func FindItem(slice []string, value string) (int, bool)

FindItem is a linear search implementation that checks if a string is contained in a slice and returns its index and a boolean The index can be used for slicing out an item from a slice.

func GetRandomName

func GetRandomName() *string

GetRandomName generates a random name from the list of adjectives and surnames in this package formatted as "adjective_surname". For example '@focused_turing23254'. If retry is non-zero, a random integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3`

func GetUserNavigationActions added in v0.0.2

func GetUserNavigationActions(
	ctx context.Context,
	user profileutils.UserProfile,
	roles []profileutils.Role,
) (*dto.GroupedNavigationActions, error)

GetUserNavigationActions returns a sorted primary and secondary user navigation actions

func GetUserPermissions added in v0.0.2

func GetUserPermissions(roles []profileutils.Role) []string

GetUserPermissions returns all the scopes of user permissions

func GetUserResponse

func GetUserResponse(text string) string

GetUserResponse gets the concatenated text from Africans Talking and splits it to get the current user input

func GroupNested added in v0.0.2

func GroupNested(
	actions []domain.NavigationAction,
) []domain.NavigationAction

GroupNested groups navigation actions into parents and children

func GroupPriority added in v0.0.2

func GroupPriority(actions []domain.NavigationAction) (primary, secondary []domain.NavigationAction)

GroupPriority groups navigation actions into primary and secondary actions

func IsFavNavAction added in v0.0.2

func IsFavNavAction(u *profileutils.UserProfile, title string) bool

IsFavNavAction checks if user has book marked the provided navaction

func IsLetter

func IsLetter(s string) bool

IsLetter ...

func MatchAndReturn

func MatchAndReturn(old bool, new bool) bool

MatchAndReturn checks is the new is not equal to old and returns it. Otherwise the old used when setting communication settings

func NewActionsMapper added in v0.0.2

NewActionsMapper maps the new navigation actions mapper to the old navigation actions implementation It is meant to be used as a transition and ease changes made without affecting the frontend

func NewInterServiceClient

func NewInterServiceClient(serviceName string, baseExt extension.BaseExtension) *interserviceclient.InterServiceClient

NewInterServiceClient initializes an external service in the correct environment given its name

func RecordSpanError

func RecordSpanError(span trace.Span, err error)

RecordSpanError is a helper function to capture errors in a span

func RemoveDuplicateStrings added in v0.0.2

func RemoveDuplicateStrings(strings []string) []string

RemoveDuplicateStrings removes duplicate strings from a list of strings

func ServiceHealthEndPoint

func ServiceHealthEndPoint(input string) (string, error)

ServiceHealthEndPoint creates a url to the service health endpoint

func UniquePermissionsArray

func UniquePermissionsArray(arr []profileutils.PermissionType) []profileutils.PermissionType

UniquePermissionsArray removes duplicate permissions in an array of permissions

func ValidateDateDigits

func ValidateDateDigits(pin string) error

ValidateDateDigits validates user pin to ensure a PIN only contains digits

func ValidateDateLength

func ValidateDateLength(date string) error

ValidateDateLength ensures that the dates are of only 8 numbers

func ValidatePIN

func ValidatePIN(pin string) error

ValidatePIN ...

func ValidatePINLength

func ValidatePINLength(pin string) error

ValidatePINLength ...

func ValidateRegisterUserInput added in v0.0.10

func ValidateRegisterUserInput(input dto.RegisterUserInput) (bool, error)

ValidateRegisterUserInput validates the user registration input

func ValidateSignUpInput

func ValidateSignUpInput(input *dto.SignUpInput) (*dto.SignUpInput, error)

ValidateSignUpInput returns a valid sign up input

func ValidateUID

func ValidateUID(w http.ResponseWriter, r *http.Request) (*dto.UIDPayload, error)

ValidateUID checks that the uid supplied in the indicated request is valid

func ValidateYearOfBirth

func ValidateYearOfBirth(date string) string

ValidateYearOfBirth validates that the year enter is 18 years and above

Types

type RatedHTTPClient added in v0.0.39

type RatedHTTPClient struct {
	Ratelimiter *rate.Limiter
	// contains filtered or unexported fields
}

RatedHTTPClient Rate Limited HTTP Client This client will be used in-place of the default client which may be throttled for send too many requests The usecase of this client is simple: A concurrent process that produces streams to request that the servicing server may not handle as quickly as the requests are been sent

func NewClient added in v0.0.39

func NewClient(rl *rate.Limiter) *RatedHTTPClient

NewClient return http client with a ratelimiter

func (*RatedHTTPClient) Do added in v0.0.39

func (c *RatedHTTPClient) Do(req *http.Request) (*http.Response, error)

Do dispatches the HTTP request to the network

Jump to

Keyboard shortcuts

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