go_tools

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

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

Go to latest
Published: Apr 25, 2019 License: MIT Imports: 13 Imported by: 0

README

go-tools

Instalacion

go get -u github.com/ing-developers/go-tools

Conjunto de herramientas para go

  1. Limpieza de cache en peticiones Http
  2. Validaciones en formularios
  3. Decodificar json a struct
  4. Decodificar request body a struct
  5. Renderizar template go
  6. Respuesta basica a clientes
  7. Upload archivo
  8. JWT

Documentation

Overview

* Author MALDRU * Email andres.latorre@ing-developers.com * Copyright (c) 2019. All rights reserved.

* Author MALDRU * Email andres.latorre@ing-developers.com * Copyright (c) 2019. All rights reserved.

* Author MALDRU * Email andres.latorre@ing-developers.com * Copyright (c) 2019. All rights reserved.

* Author MALDRU * Email andres.latorre@ing-developers.com * Copyright (c) 2019. All rights reserved. * Para usar la herramienta obtener la dependencia github.com/dgrijalva/jwt-go

* Author MALDRU * Email andres.latorre@ing-developers.com * Copyright (c) 2019. All rights reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanCache

func CleanCache(w http.ResponseWriter)

CleanCache Establece encabezados para evitar el cache en el navegador

func Decode

func Decode(ruta string, modelo interface{}) error

Decode mapea un archivo json a un struct

func DecodeBody

func DecodeBody(r *http.Request, modelo interface{}) error

DecodeRequest mapea una peticion con body json a un struct

func DecodeParams

func DecodeParams(r *http.Request, modelo interface{}) error

DecodeRequest mapea una peticion con body json a un struct

func EsNumerico

func EsNumerico(valor string) bool

EsNumerico valida si es un numero valido

func RenderTemplate

func RenderTemplate(w http.ResponseWriter, data interface{}, multiples bool, layout string, tpl ...string)

RenderTemplate renderiza template

func Responder

func Responder(w http.ResponseWriter, estado int, error interface{}, mensaje string, datos interface{}, esJSON bool, debug bool)

Responder escribe en el response la respuesta establecida

func ValidarLongitud

func ValidarLongitud(valor string, min, max int) bool

ValidarLongitud valida la longitud de un string en un rango especificado, si max es 0 no se toma en cuenta el maximo

func ValidarValoresPosibles

func ValidarValoresPosibles(valor string, posibles ...string) bool

ValidarValoresPosibles valida que el valor este entre algun posible valor

Types

type Claim

type Claim struct {
	Sesion interface{}
	jwt.StandardClaims
}

Claim modelo para las peticiones

type JWT

type JWT struct {
	RutaPrivateKey string
	RutaPublicKey  string
}

func (JWT) GenerarTokenSesion

func (j JWT) GenerarTokenSesion(payload interface{}, modulo string, vencimientoHoras int) (string, error)

GenerarTokenSesion genera token firmado con claim personalizado

func (JWT) ValidarToken

func (j JWT) ValidarToken(tokenGen string) (sesion Claim, err error)

ValidarToken valida token valido

type UploadSetup

type UploadSetup struct {
	NameInput           string
	MimesType           []string
	PermitirExtenciones bool
	RutaArchivos        string
	LimiteUpload        float32
}

UploadSetup Configuracion Upload

func (UploadSetup) Upload

func (u UploadSetup) Upload(r *http.Request, name string) error

Upload sube un archivo a la carpeta indicada en el servidor

Jump to

Keyboard shortcuts

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