converterandformatter

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 15 Imported by: 22

README

Build Status Maintained Linting and Tests Coverage Status

Converters and Formatters

converterandformatter is a utils package that contains helper functions that takes an input and transforms it to a different output

Installing it

converterandformatter is compatible with modern Go releases in module mode, with Go installed:

go get -u github.com/savannahghi/converterandformatter

will resolve and add the package to the current development module, along with its dependencies.

Alternatively the same can be achieved if you use import in a package:

import "github.com/savannahghi/converterandformatter"

and run go get without parameters.

The package name is converterandformatter

Developing

The default branch library is main

We try to follow semantic versioning ( https://semver.org/ ). For that reason, every major, minor and point release should be tagged.

git tag -m "v0.0.1" "v0.0.1"
git push --tags

Continuous integration tests must pass on Travis CI. Our coverage threshold is 90% i.e you must keep coverage above 90%.

Environment variables

In order to run tests, you need to have an env.sh file similar to this one:

# Application settings
export DEBUG=true
export IS_RUNNING_TESTS=true
export SENTRY_DSN=<a Sentry Data Source Name>
export PORT=8080  # local only, set by the runtime in the cloud

# Google Cloud credentials
export GOOGLE_APPLICATION_CREDENTIALS="<path to a service account JSON file"
export GOOGLE_CLOUD_PROJECT="Google Cloud project id"
export FIREBASE_WEB_API_KEY="<a web API key that corresponds to the project named above>"

# Link shortening
export FIREBASE_DYNAMIC_LINKS_DOMAIN=https://bwlci.page.link

This file must not be committed to version control.

It is important to export the environment variables. If they are not exported, they will not be visible to child processes e.g go test ./....

These environment variables should also be set up on Travis CI environment variable section.

Contributing

I would like to cover the entire GitHub API and contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward. See CONTRIBUTING.md for details.

Versioning

In general, converterandformatter follows semver as closely as we can for tagging releases of the package. For self-contained libraries, the application of semantic versioning is relatively straightforward and generally understood. We've adopted the following versioning policy:

  • We increment the major version with any incompatible change to non-preview functionality, including changes to the exported Go API surface or behavior of the API.
  • We increment the minor version with any backwards-compatible changes to functionality, as well as any changes to preview functionality in the GitHub API. GitHub makes no guarantee about the stability of preview functionality, so neither do we consider it a stable part of the go-github API.
  • We increment the patch version with any backwards-compatible bug fixes.

License

This library is distributed under the MIT license found in the LICENSE file.

Documentation

Index

Constants

View Source
const (

	// OTPCollectionName is the name of the collection used to persist single
	// use verification codes on Firebase
	OTPCollectionName = "otps"

	// PhoneOptInCollectionName ...
	PhoneOptInCollectionName = "phone_opt_ins"

	//USSDSessionCollectionName ...
	USSDSessionCollectionName = "ussd_signup_sessions"
)

Variables

This section is empty.

Functions

func ConvertInterfaceMap added in v0.0.6

func ConvertInterfaceMap(inp map[string]interface{}) map[string]string

ConvertInterfaceMap converts a map[string]interface{} to a map[string]string.

Any conversion errors are written out to the output map instead of being returned as error values.

New code is discouraged from using this function.

func ConvertStringMap added in v0.0.9

func ConvertStringMap(inp map[string]string) map[string]interface{}

ConvertStringMap converts a map[string]string to a map[string]interface{}.

This is done mostly in order to conform to the gqlgen Graphql Map scalar.

func GenerateRandomEmail added in v0.0.4

func GenerateRandomEmail() string

GenerateRandomEmail allows us to get "unique" emails while still keeping one main be.well@bewell.co.ke email account

func GenerateRandomWithNDigits added in v0.0.4

func GenerateRandomWithNDigits(numberOfDigits int) (string, error)

GenerateRandomWithNDigits - given a digit generate random numbers

func IntSliceContains added in v0.0.5

func IntSliceContains(s []int, e int) bool

IntSliceContains tests if a string is contained in a slice of strings

func IsMSISDNValid

func IsMSISDNValid(msisdn string) bool

IsMSISDNValid uses regular expression to validate the a phone number

func MapInterfaceToMapString added in v0.0.9

func MapInterfaceToMapString(in map[string]interface{}) (map[string]string, error)

MapInterfaceToMapString converts a map with interface{} values to one with string values.

It is used to convert a GraphQL (gqlgen) input Map to a map of strings for APIs that need map[string]string.

func NormalizeMSISDN

func NormalizeMSISDN(msisdn string) (*string, error)

NormalizeMSISDN validates the input phone number. For valid phone numbers, it normalizes them to international format e.g +2547........

func StringSliceContains

func StringSliceContains(s []string, e string) bool

StringSliceContains tests if a string is contained in a slice of strings

func StructToMap added in v0.0.4

func StructToMap(item interface{}) (map[string]interface{}, error)

StructToMap converts an object (struct) to a map.

WARNING: int inputs are converted to floats in the output map. This is an unintended consequence of converting through JSON.

In future, this should be deprecated.

func ValidateAndSaveMSISDN

func ValidateAndSaveMSISDN(
	msisdn, verificationCode string, isUSSD bool, optIn bool,
	firestoreClient *firestore.Client) (string, error)

ValidateAndSaveMSISDN returns an error if the MSISDN format is wrong or the supplied verification code is not valid

func ValidateMSISDN

func ValidateMSISDN(
	msisdn, verificationCode string,
	isUSSD bool, firestoreClient *firestore.Client) (string, error)

ValidateMSISDN returns an error if the MSISDN format is wrong or the supplied verification code is not valid Deprecated: Should implement `VerifyOTP` instead. This helps to confirm if a phonenumber is valid by verifying the code sent to it.

Types

type PhoneOptIn

type PhoneOptIn struct {
	MSISDN  string `json:"msisdn" firestore:"msisdn"`
	OptedIn bool   `json:"optedIn" firestore:"optedIn"`
}

PhoneOptIn is used to persist and manage phone communication whitelists

func (PhoneOptIn) IsEntity

func (p PhoneOptIn) IsEntity()

IsEntity ...

type USSDSessionLog

type USSDSessionLog struct {
	MSISDN    string `json:"msisdn" firestore:"msisdn"`
	SessionID string `json:"sessionID" firestore:"sessionID"`
}

USSDSessionLog is used to persist a log of USSD sessions

func (USSDSessionLog) IsEntity

func (p USSDSessionLog) IsEntity()

IsEntity ...

Jump to

Keyboard shortcuts

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