utils

package
v0.0.0-...-d26b62e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisconnectClient

func DisconnectClient(logger *zap.SugaredLogger, client *mongo.Client)

func FromFormURLEncoded

func FromFormURLEncoded(i interface{}, r map[string][]string) error

FromFormURLEncoded decodes objects form a parsed form

func FromFormURLEncodedRequest

func FromFormURLEncodedRequest(i interface{}, r *http.Request) error

FromFormURLEncodedRequest decodes objects from a form url encoded request

func FromJSON

func FromJSON(i interface{}, r io.Reader) error

FromJSON decodes objects from an io.Reader

func GetIP

func GetIP(r *http.Request) string

GetIP gets a requests IP address by reading off the forwarded-for header (for proxies) and falls back to use the remote address.

func RespondWithError

func RespondWithError(rw http.ResponseWriter, code int, message string) error

func StartGracefully

func StartGracefully(logger *zap.SugaredLogger, server *http.Server, timeoutDuration time.Duration)

StartGracefully starts a http server on another go routine so when an interrupt signal hits, a timout is initialized and all active requests can be handled before shutting down.

func StartGrpcGracefully

func StartGrpcGracefully(logger *zap.SugaredLogger, server *grpc.Server, listener net.Listener)

StartGrpcGracefully starts a grpc server on another go routine so when an interrupt signal hits, a timout is initialized and all active requests can be handled before shutting down.

func StartMongoServer

func StartMongoServer(url, databaseName string, timeout time.Duration) (*mgm.Config, *mongo.Client, *mongo.Database, error)

func StartMongoServerWithFatal

func StartMongoServerWithFatal(logger *zap.SugaredLogger, url, databaseName string, timeout time.Duration) (*mgm.Config, *mongo.Client, *mongo.Database)

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

ToJSON encodes objects and writes them using the specified io.Writer

Types

This section is empty.

Jump to

Keyboard shortcuts

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