metadata

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package metadata contains metadata storage used across buypal application.

Package metadata contains a metadata store used across multiple services. It is used to pass the headers from the request to other services.

Index

Constants

View Source
const (
	KeyContentLanguage = "contentLanguage"
	KeyAcceptLanguages = "acceptLanguage"
	KeyCurrency        = "currency"
	KeyUserID          = "userId"
	KeyToken           = "token"
	KeyContentEncoding = "contentEncoding"
	KeyRemoteIP        = "remoteIp"
	KeyRequestID       = "requestId"
)

Constant metadata key definitions.

Variables

This section is empty.

Functions

func AcceptLanguage

func AcceptLanguage(ctx context.Context) (language.Tag, bool)

AcceptLanguage gets the first accepted language stored in the context metadata.

func AcceptLanguages

func AcceptLanguages(ctx context.Context) ([]language.Tag, bool)

AcceptLanguages gets the accepted languages stored in the context metadata.

func ContentLanguage

func ContentLanguage(ctx context.Context) (language.Tag, bool)

ContentLanguage gets the content language from the context metadata.

func Get

func Get(ctx context.Context, key string) (string, bool)

Get gets the data from the Meta map.

func MergeContext

func MergeContext(ctx context.Context, patchMd Meta, overwrite bool) context.Context

MergeContext merges metadata to existing metadata, overwriting if specified

func NewContext

func NewContext(ctx context.Context, md Meta) context.Context

NewContext creates a new context with the given metadata

func RemoteIP

func RemoteIP(ctx context.Context) (string, bool)

RemoteIP gets metadata remote ip.

func RequestID

func RequestID(ctx context.Context) (string, bool)

func Token

func Token(ctx context.Context) (string, bool)

Token gets metadata token.

func UserID

func UserID(ctx context.Context) (string, bool)

UserID gets metadata userID.

Types

type Meta

type Meta map[string]string

Meta is the metadata container used in the flow of applications.

func FromContext

func FromContext(ctx context.Context) (Meta, bool)

FromContext gets the metadata from the context.

func MustFromContext

func MustFromContext(ctx context.Context) Meta

MustFromContext gets the metadata from the context.

func (Meta) AcceptLanguage

func (m Meta) AcceptLanguage() (language.Tag, bool)

AcceptLanguage gets accepted language with the highest quality.

func (Meta) AcceptLanguages

func (m Meta) AcceptLanguages() ([]language.Tag, bool)

AcceptLanguages gets accepted languages by the user stored by the quality.

func (Meta) ContentEncoding

func (m Meta) ContentEncoding() (string, bool)

ContentEncoding sets the content encoding.

func (Meta) ContentLanguage

func (m Meta) ContentLanguage() (language.Tag, bool)

ContentLanguage gets the content language from the metadata.

func (Meta) Currency

func (m Meta) Currency() (currency.Unit, bool)

Currency gets the currency from the map.

func (Meta) Delete

func (m Meta) Delete(key string)

Delete clears the key in the given metadata.

func (Meta) Get

func (m Meta) Get(key string) (string, bool)

Get gets the key from the given metadata.

func (Meta) RemoteIP

func (m Meta) RemoteIP() (string, bool)

RemoteIP gets the remote IP from the metadata.

func (Meta) RequestID

func (m Meta) RequestID() (string, bool)

RequestID gets the request id from the metadata.

func (Meta) Set

func (m Meta) Set(key, value string)

Set sets the key in the given metadata.

func (Meta) SetAcceptLanguages

func (m Meta) SetAcceptLanguages(tags []language.Tag)

SetAcceptLanguages sets up request accepted languages by the user with the quality order.

func (Meta) SetContentEncoding

func (m Meta) SetContentEncoding(encoding string)

SetContentEncoding sets the content encoding.

func (Meta) SetContentLanguage

func (m Meta) SetContentLanguage(tag language.Tag)

SetContentLanguage sets up language metadata.

func (Meta) SetCurrency

func (m Meta) SetCurrency(c currency.Unit)

SetCurrency sets up currency metadata.

func (Meta) SetRemoteIP

func (m Meta) SetRemoteIP(remoteIP string)

SetRemoteIP sets the remoteIP in the metadata.

func (Meta) SetRequestID

func (m Meta) SetRequestID(requestID string)

SetRequestID sets the request id in the metadata.

func (Meta) SetToken

func (m Meta) SetToken(token string)

SetToken sets the token in the metadata context.

func (Meta) SetUserID

func (m Meta) SetUserID(userID string)

SetUserID sets up user id

func (Meta) Token

func (m Meta) Token() (string, bool)

Token gets the token from the metadata.

func (Meta) UserID

func (m Meta) UserID() (string, bool)

UserID gets the user id from the metadata.

Jump to

Keyboard shortcuts

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