u

package module
v0.0.0-...-f945018 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 12 Imported by: 1

README

UTIL27

A utility library with very few dependencies.

Go documentation

package u // import "github.com/harkaitz/go-u27"

var FakedTime time.Time
var FakedTimeEnabled bool = false
var TranslateFunction func(fr string, lang string) string = nil
var VerboseRPC bool = os.Getenv("VERBOSE_RPC") != ""
func AddError(el *[]error, e ...error)
func AddErrorE(el *[]error, e error, f string)
func AddErrorF(el *[]error, s string, f string)
func AtExit(f func())
func Cleanup()
func Err(err error)
func ErrS(msg string)
func Exit(i int, errs ...error)
func FormValidAddress(s string) bool
func FormValidName(s string) bool
func GetErrorField(err error) (s string, b bool)
func GetErrorMessage(err error, lang ...string) (msg, field string)
func GetFromCache(id string, exp int64, out any) (found bool)
func IsError(oB []byte) (err error)
func JoinErrors(errl []error, nl string) (e error)
func Money(i, j money.Amount) (o money.Amount)
func MoneyStr(o money.Amount, c string, l string) (s string)
func NewSystemError(msg string) (e error)
func NewUserError(msg string, field string) (e error)
func Now() time.Time
func SaveToCache(id string, in any)
func StrMoney(s string, min, max money.Amount) (amount money.Amount, err error)
func StrTime(lang string, s string) (time.Time, error)
func T(fr string) string
func Translate(t string, lang ...string) string
func UnauthorizedError() error
func UntrustedError() error
type RPC struct{ ... }
type RPCRequest struct{ ... }
type RPCResponse struct{ ... }

Collaborating

For making bug reports, feature requests and donations visit one of the following links:

  1. gemini://harkadev.com/oss/
  2. https://harkadev.com/oss/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FakedTime time.Time
View Source
var FakedTimeEnabled bool = false
View Source
var TranslateFunction func(fr string, lang string) string = nil

TranslateFunction can be replaced by the user to specify how to translate texts.

View Source
var VerboseRPC bool = os.Getenv("VERBOSE_RPC") != ""

Functions

func AddError

func AddError(el *[]error, e ...error)

func AddErrorE

func AddErrorE(el *[]error, e error, f string)

func AddErrorF

func AddErrorF(el *[]error, s string, f string)

func AtExit

func AtExit(f func())

AtExit adds a function to the list of functions to be executed when exiting program with Cleanup().

func Cleanup

func Cleanup()

Cleanup executes the functions added with AtExit().

func Err

func Err(err error)

func ErrS

func ErrS(msg string)

func Exit

func Exit(i int, errs ...error)

Exit executes Cleanup and exists the program.

func FormValidAddress

func FormValidAddress(s string) bool

func FormValidName

func FormValidName(s string) bool

func GetErrorField

func GetErrorField(err error) (s string, b bool)

func GetErrorMessage

func GetErrorMessage(err error, lang ...string) (msg, field string)

func GetFromCache

func GetFromCache(id string, exp int64, out any) (found bool)

func IsError

func IsError(oB []byte) (err error)

func JoinErrors

func JoinErrors(errl []error, nl string) (e error)

func Money

func Money(i, j money.Amount) (o money.Amount)

Money converts Money(3,60) to 360.

func MoneyStr

func MoneyStr(o money.Amount, c string, l string) (s string)

MoneyStr prints the amount in human form.

func NewSystemError

func NewSystemError(msg string) (e error)

func NewUserError

func NewUserError(msg string, field string) (e error)

func Now

func Now() time.Time

Now is the same as time.Now() but you can fake the time by setting FAKETIME = "YYYY-MM-DD".

func SaveToCache

func SaveToCache(id string, in any)

func StrMoney

func StrMoney(s string, min, max money.Amount) (amount money.Amount, err error)

StrMoney .

func StrTime

func StrTime(lang string, s string) (time.Time, error)

StrTime .

func T

func T(fr string) string

T marks a string as translatable. Can be used to extract internationalizable texts from the program.

func Translate

func Translate(t string, lang ...string) string

Translate uses the TranslateFunction set by the user to query translations.

func UnauthorizedError

func UnauthorizedError() error

func UntrustedError

func UntrustedError() error

Types

type RPC

type RPC struct {
	URL  string
	User string
	Pass string
}

func (*RPC) RPCQuery

func (c *RPC) RPCQuery(httpPath, httpMethod, rpcMethod string, in any, out any) (err error)

func (*RPC) SimQuery

func (c *RPC) SimQuery(httpPath, httpMethod string, out any) (err error)

type RPCRequest

type RPCRequest struct {
	JsonRPC string      `json:"jsonrpc"`
	ID      string      `json:"id"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

type RPCResponse

type RPCResponse struct {
	Error struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
	Result interface{} `json:"result"`
}

Jump to

Keyboard shortcuts

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