env

package
v0.0.0-...-82e7740 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 6 Imported by: 6

README

comm-env GoDoc

environment library for Go

Installation

go get gopkg.in/goyy/goyy.v0/comm/env

Usage

db, _ := env.Database("env")
fmt.Println(db.DriverName)
fmt.Println(db.DataSourceName)
// Output:
// mysql
// root:root@/env_development?charset=utf8

m, _ := env.Mail("env")
fmt.Println(m.Secret)
fmt.Println(m.Protocol)
fmt.Println(m.Username)
fmt.Println(m.Password)
fmt.Println(m.Host)
fmt.Println(m.Port)
// Output:
// 0ae36a2eha9p1e16
// POP3
// username@example.com
// password
// mail.example.com
// 110

Documentation

Overview

Package env implements environment configuration utility functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetConf

func SetConf(path string)

SetConf set the root directory of the configuration file. Default value is "./conf".

func SetLocale

func SetLocale(locale string)

SetLocale set the i18n locale.

Types

type Api

type Api struct {
	Name string `xml:"name,attr"`
	URL  string `xml:"url"`
}

Api api.

func ParseApi

func ParseApi(name string) (out Api, err error)

ParseApi get the api based on the environment profiles.

type Configuration

type Configuration struct {
	Settings     Settings     `xml:"settings"`
	Environments Environments `xml:"environments"`
}

Configuration configuration.

type Database

type Database struct {
	Name           string `xml:"name,attr"`
	DriverName     string `xml:"driverName"`
	DataSourceName string `xml:"dataSourceName"`
	MaxIdleConns   int    `xml:"maxIdleConns"`
	MaxOpenConns   int    `xml:"maxOpenConns"`
}

Database database.

func ParseDatabase

func ParseDatabase(name string) (out Database, err error)

ParseDatabase get the database link parameters based on the environment profiles.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/comm/env"
)

func main() {
	db, _ := env.ParseDatabase("env")
	fmt.Println(db.DriverName)
	fmt.Println(db.DataSourceName)
	fmt.Println(db.MaxIdleConns)
	fmt.Println(db.MaxOpenConns)

}
Output:

mysql
root:root@/env_development?charset=utf8
10
100

type Environment

type Environment struct {
	Id         string      `xml:"id,attr"`
	Databases  []Database  `xml:"database"`
	Mails      []Mail      `xml:"mail"`
	Sessions   []Session   `xml:"session"`
	Apis       []Api       `xml:"api"`
	Assets     []Static    `xml:"asset"`
	Statics    []Static    `xml:"static"`
	Developers []Static    `xml:"developer"`
	Operations []Static    `xml:"operation"`
	Uploads    []Upload    `xml:"upload"`
	Exports    []Export    `xml:"export"`
	Htmls      []Template  `xml:"html"`
	Templates  []Template  `xml:"template"`
	Sensitives []Sensitive `xml:"sensitive"`
	Logs       []Log       `xml:"log"`
	Secures    []Secure    `xml:"secure"`
}

Environment environment.

type Environments

type Environments struct {
	Default     string        `xml:"default,attr"`
	Environment []Environment `xml:"environment"`
}

Environments environments.

type Export

type Export struct {
	Name string `xml:"name,attr"`
	Dir  string `xml:"dir"`
}

Export export.

func ParseExport

func ParseExport(name string) (out Export, err error)

ParseExport get the export based on the environment profiles.

type Filters

type Filters struct {
	InterceptUrl []InterceptUrl `xml:"intercept-url"`
}

Filters filters.

type InterceptUrl

type InterceptUrl struct {
	Pattern string `xml:"pattern,attr"`
	Access  string `xml:"access,attr"`
}

InterceptUrl interceptUrl.

type Log

type Log struct {
	Name     string `xml:"name,attr"`
	Priority int    `xml:"priority"`
	Layout   int    `xml:"layout"`
	Output   int    `xml:"output"`
	Dir      string `xml:"dir"`
}

Log log.

func ParseLog

func ParseLog(name string) (out Log, err error)

ParseLog get the log based on the environment profiles.

type Mail

type Mail struct {
	Name     string `xml:"name,attr"`
	Secret   string `xml:"secret"`
	Protocol string `xml:"protocol"`
	Username string `xml:"username"`
	Password string `xml:"password"`
	Host     string `xml:"host"`
	Port     string `xml:"port"`
}

Mail mail.

func ParseMail

func ParseMail(name string) (out Mail, err error)

ParseMail get the mail server parameters based on the environment profiles.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/comm/env"
)

func main() {
	m, _ := env.ParseMail("env")
	fmt.Println(m.Secret)
	fmt.Println(m.Protocol)
	fmt.Println(m.Username)
	fmt.Println(m.Password)
	fmt.Println(m.Host)
	fmt.Println(m.Port)

}
Output:

0ae36a2eha9p1e16
POP3
username@example.com
password
mail.example.com
110

type Mapping

type Mapping struct {
	Path string `xml:"path,attr"`
	Dir  string `xml:"dir,attr"`
}

Mapping mapping.

type Mappings

type Mappings struct {
	Mapping []Mapping `xml:"mapping"`
}

Mappings mappings.

type Profile

type Profile struct {
	Default string `xml:"default,attr"`
	Actives string `xml:"actives,attr"`
}

Profile profile.

type Secure

type Secure struct {
	Name       string  `xml:"name,attr"`
	Enable     bool    `xml:"enable"`
	LoginUrl   string  `xml:"login-url"`
	ForbidUrl  string  `xml:"forbid-url"`
	SuccessUrl string  `xml:"success-url"`
	Filters    Filters `xml:"filters"`
}

Secure secure.

func ParseSecure

func ParseSecure(name string) (out Secure, err error)

ParseSecure get the secure based on the environment profiles.

type Sensitive

type Sensitive struct {
	Name     string `xml:"name,attr"`
	Enable   bool   `xml:"enable"`
	Excludes string `xml:"excludes"`
	Values   string `xml:"values"`
}

Sensitive sensitive word.

func ParseSensitive

func ParseSensitive(name string) (out Sensitive, err error)

ParseSensitive get the sensitive word based on the environment profiles.

type Session

type Session struct {
	Name     string `xml:"name,attr"`
	Addr     string `xml:"addr"`
	Password string `xml:"password"`
}

Session session.

func ParseSession

func ParseSession(name string) (out Session, err error)

ParseSession get the session based on the environment profiles.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/comm/env"
)

func main() {
	s, _ := env.ParseSession("env")
	fmt.Println(s.Addr)
	fmt.Println(s.Password)

}
Output:

:6379
123456

type Settings

type Settings struct {
	Name    string  `xml:"name,attr"`
	Profile Profile `xml:"profile"`
}

Settings settings.

func ParseSettings

func ParseSettings() (out Settings, err error)

ParseSettings get the settings link parameters based on the configuration file.

type Static

type Static struct {
	Name     string   `xml:"name,attr"`
	Enable   bool     `xml:"enable"`
	URL      string   `xml:"url"`
	Dir      string   `xml:"dir"`
	Mappings Mappings `xml:"mappings"`
}

Static static.

func ParseAsset

func ParseAsset(name string) (out Static, err error)

ParseAsset get the asset based on the environment profiles.

func ParseDeveloper

func ParseDeveloper(name string) (out Static, err error)

ParseDeveloper get the developer based on the environment profiles.

func ParseOperation

func ParseOperation(name string) (out Static, err error)

ParseOperation get the operation based on the environment profiles.

func ParseStatic

func ParseStatic(name string) (out Static, err error)

ParseStatic get the static based on the environment profiles.

type Template

type Template struct {
	Name     string   `xml:"name,attr"`
	Enable   bool     `xml:"enable"`
	Reloaded bool     `xml:"reloaded"`
	Dir      string   `xml:"dir"`
	Mappings Mappings `xml:"mappings"`
}

Template template.

func ParseHtml

func ParseHtml(name string) (out Template, err error)

ParseHtml get the html based on the environment profiles.

func ParseTemplate

func ParseTemplate(name string) (out Template, err error)

ParseTemplate get the template based on the environment profiles.

type Upload

type Upload struct {
	Name    string `xml:"name,attr"`
	Enable  bool   `xml:"enable"`
	URL     string `xml:"url"`
	Dir     string `xml:"dir"`
	MaxSize string `xml:"maxSize"`
}

Upload upload.

func ParseUpload

func ParseUpload(name string) (out Upload, err error)

ParseUpload get the upload based on the environment profiles.

Jump to

Keyboard shortcuts

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