envparse

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2020 License: MIT Imports: 6 Imported by: 0

README

envparse

GoDev Build Status Coverage Status Go Report Card

Envparse is library for parse ENV variables written in Go.

Taken from moby/docker Dockerfile parser.

See original moby parser.

Parses env variables in form of:

<key> <value>
<key>=<value> ...

See also original ENV documentation

Quick-start

package main

import (
  "bytes"
  "fmt"

  "github.com/go-x-pkg/envparse"
)

func main() {
  env, err := envparse.Parse("LD_LIBRARY_PATH=/usr/lib:/usr/nvidia/cuda/lib64 PATH=/usr/bin:/bin")

  fmt.Println(env, err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMustHaveTwoArguments indicates key value
	// are two arguments
	ErrMustHaveTwoArguments = errors.New("must have two arguments")

	// ErrMissingEqualsSign indicates that key=value
	// pair doesn't contains = separator
	ErrMissingEqualsSign = errors.New("syntax error - can't find =. Must be of the form: name=value")
)

Functions

func ParseRaw

func ParseRaw(raw string, cb func(string, string)) error

ParseRaw is wrapper around parseRaw with default Directives

func ParseRawWithDirectives

func ParseRawWithDirectives(raw string, d *Directives, cb func(string, string)) error

ParseRawWithDirectives is wrapper around parseRaw

Types

type Directives

type Directives struct {
	EscapeToken rune // Current escape token
}

Directives is the structure used during a build run to hold the state of parsing directives.

type Env

type Env map[string]string

Env maps a string key to a list of values. see net/url/url.go

func Parse

func Parse(raw string) (Env, error)

Parse parses raw key=value pairs into Env(some sort of url.Values)

func (Env) Del

func (e Env) Del(key string)

Del deletes the values associated with key.

func (Env) Set

func (e Env) Set(key, value string)

Set sets the key to value.

func (Env) String added in v0.0.2

func (e Env) String() string

String returns string representation of Env

Jump to

Keyboard shortcuts

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