helpers

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: MIT Imports: 37 Imported by: 0

README

Helpers package for Go language

This package provides some helpers Go types & functions.

Installation

Use the go command:

$ go get github.com/srostyslav/helpers

Requirements

Helpers package tested against Go 1.16.

Example

package main

import (
    "github.com/srostyslav/helpers"
)

func main() {
    helpers.InitLogger()

    req := &helpers.Request{Url: "https://www.google.com"}
    if err := req.Get(); err != nil {
        helpers.ErrorLogger.Println(err)
    } else {
        helpers.InfoLogger.Println(req.ResponseCode)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WarningLogger *log.Logger
	InfoLogger    *log.Logger
	ErrorLogger   *log.Logger
)
View Source
var AdminBot = &adminBot{}
View Source
var Mail = &mailSender{}
View Source
var S3 = &S3Config{}

Functions

func CatchPanic

func CatchPanic(title string)

func InitLogger

func InitLogger() error

func IsEmptyUUID

func IsEmptyUUID(u uuid.UUID) bool

func IsValidObject

func IsValidObject(body interface{}, objScheme map[string]interface{}) error

func PrettyPrint

func PrettyPrint(v interface{}) (err error)

Types

type Backup

type Backup struct {
	FileName                   string
	ContainerName              string
	UserName, DBName           string
	CredentialsFile, TokenFile string
	MaxBackups                 int
}

func (*Backup) Create

func (b *Backup) Create()

type File

type File struct {
	Name string
}

func (*File) Content

func (f *File) Content() (string, error)

func (*File) Create

func (f *File) Create()

func (*File) CreateAndGet

func (f *File) CreateAndGet() (*os.File, error)

func (*File) Remove

func (f *File) Remove()

func (*File) Write

func (f *File) Write(data []byte) error

type GoogleDrive

type GoogleDrive struct {
	CredentialPath, TokenPath string
	Service                   *drive.Service
}

func (*GoogleDrive) Init

func (g *GoogleDrive) Init() (err error)

type IPLocation

type IPLocation struct {
	Country  string  `json:"country"`
	IP       string  `json:"ip"`
	Postal   string  `json:"postal"`
	Lat      float64 `json:"lat"`
	Lon      float64 `json:"lon"`
	Timezone string  `json:"timezone"`
	Org      string  `json:"org"`
	City     string  `json:"city"`
	Hostname string  `json:"hostname"`
	Region   string  `json:"region"`
	Loc      string  `json:"loc"`
}

func GetIPLocation

func GetIPLocation(ip string) (*IPLocation, error)

type Request

type Request struct {
	Url             string
	Headers, Params map[string]string
	Body            interface{}
	Json            bool

	ResponseBody []byte
	ResponseCode int
	// contains filtered or unexported fields
}

func (*Request) Decode

func (r *Request) Decode(obj interface{}) error

func (*Request) Delete

func (r *Request) Delete() (err error)

func (*Request) Get

func (r *Request) Get() (err error)

func (*Request) Post

func (r *Request) Post() (err error)

func (*Request) SetClient added in v0.0.3

func (r *Request) SetClient(c *http.Client)

func (*Request) Try

func (r *Request) Try(cnt int, method string) (err error)

type S3Config

type S3Config struct {
	Key, Secret, Region, Host, Bucket string
}

func (*S3Config) Init

func (a *S3Config) Init(key, secret, region, host, bucket string)

func (*S3Config) UploadBase64

func (a *S3Config) UploadBase64(base64Image, destination string) (string, error)

func (*S3Config) UploadFile

func (a *S3Config) UploadFile(bucket, destination, imgType string, buffer []byte) (string, error)

func (*S3Config) UploadJpeg

func (a *S3Config) UploadJpeg(m image.Image, destination string) (string, error)

func (*S3Config) UploadPng

func (a *S3Config) UploadPng(m image.Image, destination string) (string, error)

type SqlQuery

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

func NewSql

func NewSql(query string, db *gorm.DB, params ...interface{}) (*SqlQuery, error)

func NewSqlFromFile

func NewSqlFromFile(fileName string, db *gorm.DB, params ...interface{}) (*SqlQuery, error)

func (*SqlQuery) Fetch

func (q *SqlQuery) Fetch(obj interface{}) (next bool, err error)

func (*SqlQuery) FetchAll

func (q *SqlQuery) FetchAll(obj interface{}) ([]interface{}, error)

func (*SqlQuery) First

func (q *SqlQuery) First(obj interface{}) error

func (*SqlQuery) ToList

func (q *SqlQuery) ToList() ([]map[string]interface{}, error)

func (*SqlQuery) Total

func (q *SqlQuery) Total() int

func (*SqlQuery) Write

func (q *SqlQuery) Write(w http.ResponseWriter, start, end string, obj interface{}) (err error)

Jump to

Keyboard shortcuts

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