shared

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package shared contains common shared information, and utilities.

Index

Constants

View Source
const (
	// Development is the development environment.
	Development = "development"

	// Integration is the integration environment.
	Integration = "integration"

	// Production is the production environment.
	Production = "production"

	// Staging is the staging environment.
	Staging = "staging"

	// Testing is the testing environment.
	Testing = "testing"
)
View Source
const (
	StatusPending = 0
	StatusActive  = 1
	StatusDeleted = 99
)

General Status Codes

View Source
const (
	// DatabaseName is the database name.
	DatabaseName = Test

	// TableName is the table/collection/index/etc name.
	TableName = Test

	// DefaultTimeout is the default timeout.
	DefaultTimeout = 30 * time.Second

	// DocumentID is the document ID.
	DocumentID = "VFzrpYMBXu5BQSZxo0qX"

	// DocumentIDInvalid is an invalid document ID.
	DocumentIDInvalid = "VFzrpYMBXu5BQSZxo0qY"

	// DocumentName is the document name.
	DocumentName = Test

	// DocumentNameUpdated is the updated document name.
	DocumentNameUpdated = "Test2"

	// DocumentVersion is the document version.
	DocumentVersion = "1.0.0"

	RoleName = "test"

	// Test name.
	Test = "test"
)
View Source
const Timeout = 30 * time.Second

Timeout is the default timeout.

Variables

View Source
var (
	// TestData is the test data.
	TestData = &TestDataS{
		Name:    DocumentName,
		Version: DocumentVersion,
	}

	// TestDataWithID is the test data.
	TestDataWithID = &TestDataWithIDS{
		ID:      DocumentID,
		Name:    DocumentName,
		Version: DocumentVersion,
	}

	// UpdatedTestData is the updated test data.
	UpdatedTestData = &TestDataS{
		Name:    DocumentNameUpdated,
		Version: DocumentVersion,
	}

	// UpdatedTestDataID is the updated test data with ID.
	UpdatedTestDataID = &TestDataWithIDS{
		ID:      DocumentID,
		Name:    DocumentNameUpdated,
		Version: DocumentVersion,
	}
)

Functions

func CreateHTTPTestServer

func CreateHTTPTestServer(
	statusCode int,
	headers map[string]string,
	queryParams map[string]string,
	body string,
) *httptest.Server

CreateHTTPTestServer creates a mocked HTTP server. Don't forget to defer close it!

SEE: Test for usage.

func Decode

func Decode(r io.Reader, v any) error

Decode process stream `r` into `v` and returns an error if any.

func ErrorContains

func ErrorContains(err error, text ...string) bool

ErrorContains checks if an error contains a string.

func GenerateID

func GenerateID(ct string) string

GenerateID generates MD5 hash (content-based) based on content. Good to be used to avoid duplicated messages.

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates a RFC4122 UUID and DCE 1.1: Authentication and Security Services.

func HasLetter

func HasLetter(s string) bool

HasLetter checks string for an alphabetic letter.

func IsEnvironment

func IsEnvironment(environments ...string) bool

IsEnvironment determines if the current environment is one of the provided.

func LettersToPhoneNumberKeys

func LettersToPhoneNumberKeys(value string) string

LettersToPhoneNumberKeys translates a given string, e.g.: `DOCTOR` to the right telephone number keys, e.g.: `362867`.

func Marshal

func Marshal(v any) ([]byte, error)

Marshal with custom error.

func PrintErrorMessages

func PrintErrorMessages(errors ...error) string

PrintErrorMessages prints the concatenated error messages.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads all the data from `r` and returns an error if any.

func SliceContains

func SliceContains(source []string, text string) bool

SliceContains returns true if the slice contains the string.

NOTE: It's case insensitive.

NOTE: @andres moved to here.

func TargetName

func TargetName(name, alternative string) (string, error)

TargetName returns the provided target name, or the configured one. A target, depending on the storage, is a collection, a table, a bucket, etc. For ElasticSearch - as it doesn't have a concept of a database - the target is the index.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal with custom error.

Types

type HTTPMethod

type HTTPMethod string

HTTPMethod is the HTTP method.

const (
	// MethodGet is the HTTP GET method.
	MethodGet HTTPMethod = http.MethodGet

	// MethodPost is the HTTP POST method.
	MethodPost HTTPMethod = http.MethodPost

	// MethodPut is the HTTP PUT method.
	MethodPut HTTPMethod = http.MethodPut

	// MethodPatch is the HTTP PATCH method.
	MethodPatch HTTPMethod = http.MethodPatch

	// MethodDelete is the HTTP DELETE method.
	MethodDelete HTTPMethod = http.MethodDelete
)

func (HTTPMethod) String

func (m HTTPMethod) String() string

type TestDataS

type TestDataS struct {
	Name    string `json:"name,omitempty" query:"name" db:"name" dbType:"varchar(255)"`
	Version string `json:"version,omitempty" query:"version" db:"version" dbType:"varchar(255)"`
}

TestDataS is the test data definition.

type TestDataWithIDS

type TestDataWithIDS struct {
	ID      string `json:"id,omitempty" query:"id" db:"id" dbType:"varchar(255)" bson:"_id"`
	Name    string `json:"name,omitempty" query:"name" db:"name" dbType:"varchar(255)"`
	Version string `json:"version,omitempty" query:"version" db:"version" dbType:"varchar(255)"`
}

TestDataWithIDS is the test data definition.

Jump to

Keyboard shortcuts

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