config

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Staging EnvironmentType
	Production

	API APIType
	SNAP

	Error LogType
	Info
	Debug

	Err002     = "required parameter is missing, "
	Err004     = "parameter has illegal value, "
	Err007     = "signature is invalid, "
	Err008     = "payement method is not available, "
	Err019     = "payment method error, "
	Err020     = "duplicate order id, "
	ErrUnknown = "unknown error, "
)

Variables

View Source
var (
	Environment        = Staging
	DefaultAPIType     = SNAP
	DefaultHttpTimeout = time.Second * time.Duration(10)
	DefaultLogLevel    = Info
	DefaultLogFormat   = "{\"timestamp\":\"%s\",\"log_type\":\"%s\",\"event\":\"%s\",\"detail\":\"%s\"}"

	DefaultHttpClient = &http.Client{Timeout: DefaultHttpTimeout}

	Logger = func(logtype LogType, event string, detail interface{}) {
		timestamp := time.Now().UTC().Format("2006-01-02 15:04:05")
		var jsonFormat []byte
		switch v := detail.(type) {
		case error:
			jsonFormat = []byte(v.Error())
		case string:
			jsonFormat = []byte(v)
		case map[string]interface{}:
			jsonFormat, _ = json.Marshal(detail)
		default:
			jsonFormat = []byte("Someting error.")
		}
		if logtype.CheckLevel() {
			newLog.Printf(DefaultLogFormat, timestamp, logtype.ToString(), event, jsonFormat)
		}
	}
)

Functions

This section is empty.

Types

type APIType

type APIType uint8

func (APIType) ToString

func (e APIType) ToString() string

type EnvironmentType

type EnvironmentType uint8

func (EnvironmentType) BaseUrl

func (e EnvironmentType) BaseUrl() string

BaseUrl To get Midtrans Base URL

type HTTPClient

type HTTPClient interface {
	RequestDo(method string, url string, bodyJson []byte, token string, signature string) ([]byte, error)
}

func GetHTTPClient

func GetHTTPClient() HTTPClient

type HttpClientImp

type HttpClientImp struct {
	HttpClient *http.Client
}

func (*HttpClientImp) RequestDo

func (c *HttpClientImp) RequestDo(method string, url string, bodyJson []byte, token string, signature string) ([]byte, error)

type LogType

type LogType uint8

func (LogType) CheckLevel

func (e LogType) CheckLevel() bool

func (LogType) ToString

func (e LogType) ToString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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