leafMandatory

package module
v0.0.0-...-0829b1e Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 8 Imported by: 9

README

Leaf Mandatory

Mandatory Object of Leaf project

Can be put and retrieved from/to context. consist of basic context data (user agent, os, request-id, request-language, device, user, etc.)

Usage

Import the package

import (
    ...
    "github.com/paulusrobin/leaf-utilities/mandatory"
    ...
)

To Retrieve mandatory from context:

func Process(ctx context.Context) {
    ...
    mandatory := leafMandatort.FromContext(ctx)
    ...
    if mandatory.User().IsLogin() {
        ...
    } else {
        ...
    }
}

Mandatory Functions:

  • TraceID() - To get TraceID / RequestID, return string
  • IpAddresses() - To get Ip Addresses, return []string
  • Language() - To request language, return string
  • Authorization() - To get Authorization Object, return leafMandatory.Authorization
    • Authorization() - To get Full Authorization, return string
    • Token() - To get Token Authorization, return string
    • ApiKey() - To get ApiKey, return string
    • ServiceID() - To get ServiceID, return string
    • ServiceSecret() - To get ServiceSecret, return string
  • DeviceType() - To get Device Category Request, return leafMandatory.DeviceType
    • ID() - To get DeviceType ID, return int
    • Name() - To get DeviceType Name, return string
    • Code() - To get DeviceType Code, return string
  • Device() - To get Device Data, return leafMandatory.Device
    • AppVersion() - To get Application version, return string
    • DeviceID() - To get Device Unique ID, return string
    • Family() - To get Device Family, return string
    • Brand() - To get Device Brand, return string
    • Model() - To get Device Model, return string
  • UserAgent() - To get User Agent Data, return leafMandatory.UserAgent
    • Value() - To get user agent Value, return string
    • Family() - To get user agent Family, return string
    • Major() - To get user agent Major version, return string
    • Minor() - To get user agent Minor version, return string
    • Patch() - To get user agent Patch version, return string
  • OS() - To get Operating System, return leafMandatory.OS
    • Name() - To get OS Name, return string
    • Version() - To get OS Version , return string
    • Family() - To get OS Family, return string
    • Major() - To get OS Major Version, return string
    • Minor() - To get OS Minor Version, return string
    • Patch() - To get OS Patch Version, return string
    • PatchMinor() - To get OS Patch Minor Version, return string
  • User() - To get User Object, return leafMandatory.User
    • ID() - To get User ID, return uint64
    • Email() - To get User Email, return string
    • IsLogin() - To get User Status is Login or not, return boolean
  • Valid() - To check mandatory object is valid or not, return boolean
  • IsUserLogin() - To get user login status, return boolean
  • IsMobileApp() - To get request is from mobile apps or not, return boolean
  • IsWebApp() - To get request is from web apps or not, return boolean

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Context

func Context(ctx context.Context, mandatory Mandatory) context.Context

Types

type Authorization

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

func (Authorization) ApiKey

func (a Authorization) ApiKey() string

func (Authorization) Authorization

func (a Authorization) Authorization() string

func (Authorization) JSON

func (a Authorization) JSON() map[string]interface{}

func (Authorization) MarshalJSON

func (a Authorization) MarshalJSON() ([]byte, error)

func (Authorization) ServiceID

func (a Authorization) ServiceID() string

func (Authorization) ServiceSecret

func (a Authorization) ServiceSecret() string

func (Authorization) Token

func (a Authorization) Token() string

type Device

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

func (Device) AppVersion

func (d Device) AppVersion() string

func (Device) Brand

func (d Device) Brand() string

func (Device) DeviceID

func (d Device) DeviceID() string

func (Device) Family

func (d Device) Family() string

func (Device) JSON

func (d Device) JSON() map[string]interface{}

func (Device) Model

func (d Device) Model() string

type DeviceInfo

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

func (DeviceInfo) Code

func (d DeviceInfo) Code() string

func (DeviceInfo) ID

func (d DeviceInfo) ID() DeviceType

func (DeviceInfo) JSON

func (d DeviceInfo) JSON() map[string]interface{}

func (DeviceInfo) Name

func (d DeviceInfo) Name() string

type DeviceType

type DeviceType int
const (
	Android DeviceType = iota + 1
	Ios
	Web
	MobileWeb
)

func DeviceFromString

func DeviceFromString(str string) (DeviceType, error)

func DeviceFromStringCode

func DeviceFromStringCode(str string) (DeviceType, error)

func (DeviceType) Info

func (s DeviceType) Info() DeviceInfo

func (DeviceType) JSON

func (s DeviceType) JSON() map[string]interface{}

func (DeviceType) MarshalJSON

func (s DeviceType) MarshalJSON() ([]byte, error)

func (*DeviceType) Scan

func (s *DeviceType) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*DeviceType) UnmarshalJSON

func (s *DeviceType) UnmarshalJSON(b []byte) error

func (DeviceType) Value

func (s DeviceType) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Mandatory

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

func FromContext

func FromContext(ctx context.Context) Mandatory

func (Mandatory) Authorization

func (m Mandatory) Authorization() Authorization

func (Mandatory) Device

func (m Mandatory) Device() Device

func (Mandatory) DeviceType

func (m Mandatory) DeviceType() DeviceType

func (Mandatory) IpAddresses

func (m Mandatory) IpAddresses() []string

func (Mandatory) IsMobileApp

func (m Mandatory) IsMobileApp() bool

func (Mandatory) IsUserLogin

func (m Mandatory) IsUserLogin() bool

func (Mandatory) IsWebApp

func (m Mandatory) IsWebApp() bool

func (Mandatory) JSON

func (m Mandatory) JSON() map[string]interface{}

===========================

Utilities Function

===========================

func (Mandatory) Language

func (m Mandatory) Language() string

func (Mandatory) OS

func (m Mandatory) OS() OS

func (Mandatory) TraceID

func (m Mandatory) TraceID() string

func (Mandatory) User

func (m Mandatory) User() User

func (Mandatory) UserAgent

func (m Mandatory) UserAgent() UserAgent

func (Mandatory) Valid

func (m Mandatory) Valid() bool

type MandatoryBuilder

type MandatoryBuilder struct {
	Mandatory
	// contains filtered or unexported fields
}

func NewMandatoryBuilder

func NewMandatoryBuilder() (MandatoryBuilder, error)

func (MandatoryBuilder) Build

func (m MandatoryBuilder) Build() Mandatory

func (MandatoryBuilder) WithApiKey

func (m MandatoryBuilder) WithApiKey(apiKey string) MandatoryBuilder

func (MandatoryBuilder) WithApplication

func (m MandatoryBuilder) WithApplication(deviceID, appsVersion string) MandatoryBuilder

func (MandatoryBuilder) WithAuthorization

func (m MandatoryBuilder) WithAuthorization(authorization string) MandatoryBuilder

func (MandatoryBuilder) WithDeviceType

func (m MandatoryBuilder) WithDeviceType(deviceType string) MandatoryBuilder

func (MandatoryBuilder) WithIpAddresses

func (m MandatoryBuilder) WithIpAddresses(ipAddress []string) MandatoryBuilder

func (MandatoryBuilder) WithLanguage

func (m MandatoryBuilder) WithLanguage(language string) MandatoryBuilder

func (MandatoryBuilder) WithPhone

func (m MandatoryBuilder) WithPhone(ID uint64, phone string) MandatoryBuilder

func (MandatoryBuilder) WithServiceSecret

func (m MandatoryBuilder) WithServiceSecret(ID, secret string) MandatoryBuilder

func (MandatoryBuilder) WithTraceID

func (m MandatoryBuilder) WithTraceID(traceID string) MandatoryBuilder

func (MandatoryBuilder) WithUser

func (m MandatoryBuilder) WithUser(ID uint64, email string) MandatoryBuilder

func (MandatoryBuilder) WithUserAgent

func (m MandatoryBuilder) WithUserAgent(userAgent string) MandatoryBuilder

func (MandatoryBuilder) WithUserPhone

func (m MandatoryBuilder) WithUserPhone(ID uint64, email string, phone string) MandatoryBuilder

type OS

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

func (OS) Family

func (o OS) Family() string

func (OS) JSON

func (o OS) JSON() map[string]interface{}

func (OS) Major

func (o OS) Major() string

func (OS) Minor

func (o OS) Minor() string

func (OS) Name

func (o OS) Name() string

func (OS) Patch

func (o OS) Patch() string

func (OS) PatchMinor

func (o OS) PatchMinor() string

func (OS) Version

func (o OS) Version() string

type User

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

func (User) Email

func (u User) Email() string

func (User) ID

func (u User) ID() uint64

func (User) IsLogin

func (u User) IsLogin() bool

func (User) JSON

func (u User) JSON() map[string]interface{}

func (User) Phone

func (u User) Phone() string

type UserAgent

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

func (UserAgent) Family

func (u UserAgent) Family() string

func (UserAgent) JSON

func (u UserAgent) JSON() map[string]interface{}

func (UserAgent) Major

func (u UserAgent) Major() string

func (UserAgent) Minor

func (u UserAgent) Minor() string

func (UserAgent) Patch

func (u UserAgent) Patch() string

func (UserAgent) Value

func (u UserAgent) Value() string

Jump to

Keyboard shortcuts

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