addons

package module
v0.0.0-...-137c120 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2021 License: MIT Imports: 9 Imported by: 0

README

go-addons

Additional golang functions, it's like a toolbox and not have a strict order. Not for production projects, if you want import some function, copy the code and paste in your project; this package not have any type support.

Documentation

Overview

Extra functions for golang

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllHeaders

func AllHeaders(w *http.ResponseWriter)

AllHeaders es equivalente a "Access-Control-Allow-Headers: *"

func AllMethods

func AllMethods(w *http.ResponseWriter)

AllMethods es equivalente a "Access-Control-Allow-Methods: *"

func AllOrigin

func AllOrigin(w *http.ResponseWriter)

AllOrigin es equivalente a "Access-Control-Allow-Origin: *"

func ApplicationJson

func ApplicationJson(w *http.ResponseWriter)

ApplicationJson es equivalente a "Content-Type: application/json; charset=utf-8*"

func Command

func Command(name string, arg ...string) error

Ejecuta una serie de comandos CLI.

func ComparePasswordHash

func ComparePasswordHash(password string, hash string) error

ComparePasswordHash verifica los una contraseña en string y un hash en string, devuelve un error si estos no coinciden.

func DeleteRequest

func DeleteRequest(url, token string, body []byte) (*http.Response, error)

WARNING: Esta función permite conectarse a dominios con certificado autofirmado. Utilizar solo en dominios de confianza.

DeleteRequest realiza una request con el método PUT con autorización tipo Bearer token.

EXAMPLE:

	body := struct {
		ID string `json:"id"`
	}{ ID: "MyElementID" }
	data, _ := json.Marshal(body)

 response, err := DeleteRequest("https://example.com", "my.awesome.Token", data)

func FloatAppend

func FloatAppend(slice []float64, addon float64) []float64

FloatAppend permite insertar un float64 a un slice tras comprobar que es mayor que 0

func IntAppend

func IntAppend(slice []int64, addon int64) []int64

IntAppend permite insertar un int64 a un slice tras comprobar que es mayor que 0

func IsLinux

func IsLinux() bool

Indica si se está trabajando sobre Linux

func IsOSX

func IsOSX() bool

func IsWASM

func IsWASM() bool

Indica si se está trabajando sobre WebAssembly

func IsWindows

func IsWindows() bool

Indica si se está trabajando sobre Windows

func PostRequest

func PostRequest(url, token string, body []byte) (*http.Response, error)

WARNING: Esta función permite conectarse a dominios con certificado autofirmado. Utilizar solo en dominios de confianza.

PostRequest realiza una request con el método POST con autorización tipo Bearer token.

EXAMPLE:

	body := struct {
		Message string `json:"message"`
	}{ Message: "Hola Mundo" }
	data, _ := json.Marshal(body)

 response, err := PostRequest("https://example.com", "my.awesome.Token", data)

func PutRequest

func PutRequest(url, token string, body []byte) (*http.Response, error)

WARNING: Esta función permite conectarse a dominios con certificado autofirmado. Utilizar solo en dominios de confianza.

PutRequest realiza una request con el método PUT con autorización tipo Bearer token.

EXAMPLE:

	body := struct {
		Message string `json:"message"`
	}{ Message: "Hola Mundo" }
	data, _ := json.Marshal(body)

 response, err := PutRequest("https://example.com", "my.awesome.Token", data)

func ReadJSONFile

func ReadJSONFile(name string, v interface{}) (content string, err error)

Lee un archivo tipo JSON, de la ubicación indicada en el parámetro name, e intenta convertirlo a un struct. , retorna el contenido del archivo ─de encontrarlo─ y un error.

func StringAppend

func StringAppend(slice []string, addon string) []string

StringAppend permite insertar un string a slice tras comprobar si existe una entrada similar.

Types

type Route

type Route struct {
	Name       string
	Methods    []string
	Pattern    string
	HandleFunc http.HandlerFunc
}

Route es un objeto que contiene los datos para crear una ruta en una API REST, puede utilizarse en conjunto con el objeto Router de github.com/gorilla/mux.

Jump to

Keyboard shortcuts

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