viper

package module
v0.0.0-...-c0075a2 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 4 Imported by: 1

README

file config

parsing the configuration file by viper

Usage

package main

import (
	"fmt"

	"github.com/segmentfault/pacman/contrib/conf/viper"
)

func main() {
	c := &AllConfig{}
	config, err := viper.NewWithPath("/config/path")
	if err != nil {
		panic(err)
	}
	if err = config.Parse(&c); err != nil {
		panic(err)
	}
	fmt.Println(c.Server.HTTP)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStaticConfigParser

func NewStaticConfigParser(path string) *file

NewStaticConfigParser create config parser

func NewWithPath

func NewWithPath(filePath string) (c conf.Config, err error)

NewWithPath to create config from specified path

Types

type FileConfig

type FileConfig struct {
	Path string `json:"path"`
	// contains filtered or unexported fields
}

func (*FileConfig) Get

func (c *FileConfig) Get(s string) any

func (*FileConfig) GetBool

func (c *FileConfig) GetBool(key string) bool

func (*FileConfig) GetInt

func (c *FileConfig) GetInt(s string) int

func (*FileConfig) GetString

func (c *FileConfig) GetString(key string) string

func (*FileConfig) Parse

func (c *FileConfig) Parse(obj any) error

Parse parses the configuration by object pointer

Jump to

Keyboard shortcuts

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