parsers

package
v3.5.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 3 Imported by: 0

README

parsers

This directory contains pre-built, custom parsers that can be used with env.ParseWithFuncs to facilitate the parsing of envs that are not basic types.

Example Usage:

package main

import (
	"fmt"
	"log"
	"net/url"

	"github.com/caarlos0/env"
	"github.com/caarlos0/env/parsers"
)

type config struct {
	ExampleURL url.URL `env:"EXAMPLE_URL" envDefault:"https://google.com"`
}

func main() {
	cfg := config{}

	if err := env.ParseWithFuncs(&cfg, env.CustomParsers{
		parsers.URLType: parsers.URLFunc,
	}); err != nil {
		log.Fatal("Unable to parse envs: ", err)
	}

	fmt.Printf("Scheme: %v Host: %v\n", cfg.ExampleURL.Scheme, cfg.ExampleURL.Host)
}

Documentation

Overview

Package parsers contains custom parser funcs for common, non-built-in types

Index

Constants

This section is empty.

Variables

View Source
var (
	// URLType is a helper var that represents the `reflect.Type“ of `url.URL`
	URLType = reflect.TypeOf(url.URL{})
)

Functions

func URLFunc

func URLFunc(v string) (interface{}, error)

URLFunc is a basic parser for the url.URL type that should be used with `env.ParseWithFuncs()`

Types

This section is empty.

Jump to

Keyboard shortcuts

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