initializr

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

Install

go get -u github.com/gota33/initializr

Example

package main

import (
	"log"

	"github.com/gofiber/fiber/v2"
	"github.com/gota33/initializr"
	fiber2 "github.com/gota33/initializr/fiber/v2"
)

func main() {
	ctx, cancel := initializr.GracefulContext()
	defer cancel()

	server, listen, shutdown := fiber2.New(":8080")

	server.Get("hello", func(c *fiber.Ctx) error {
		return c.SendString("Hello")
	})

	if err := initializr.Run(ctx, listen, shutdown); err != nil {
		log.Fatalf("Exit with error: %v", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeferClose added in v0.3.1

func DeferClose(ctx context.Context, name string, conn io.Closer)

func GracefulContext

func GracefulContext() (context.Context, func())

func Run

func Run(ctx context.Context, start func() error, stops ...func()) (err error)

Types

type Configuration added in v0.3.0

type Configuration interface {
	Scan(key string, target any) error
	MustScan(key string, target any, provide func() any)
	Get(key string) Configuration
	Exists() bool
	AsString(defaultValue string) string
	AsDuration(defaultValue time.Duration) time.Duration
	AsInt64(defaultValue int64) int64
	AsFloat64(defaultValue float64) float64
	AsBoolean(defaultValue bool) bool
	AsMap(defaultValue map[string]Configuration) map[string]Configuration
	AsArray(defaultValue []Configuration) []Configuration
	AsUrlValues(defaultValue url.Values) url.Values
}

func FromJson

func FromJson(reader io.Reader) (res Configuration, err error)

func FromJsonRemote

func FromJsonRemote(url string) (res Configuration, err error)

func FromJsonRemoteCtx added in v0.3.0

func FromJsonRemoteCtx(ctx context.Context, url string) (res Configuration, err error)

Directories

Path Synopsis
cmd
internal
log

Jump to

Keyboard shortcuts

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