GithubHelp home page GithubHelp logo

srun4-config's Introduction

srun4-config

读取srun配置

Config 包

Config 包提供了从 srun.conf 和 system.conf 文件中读取和管理配置的功能。

安装

使用以下命令安装包:

go get -u github.com/Eros-Vertigo/srun4-config

使用方法

在你的 Go 代码中导入该包:

import (
"fmt"

    "github.com/Eros-Vertigo/srun4-config"
)

初始化

config.GetConfig("/path/to/config/dir")

默认情况下,该包假设为生产环境,并从预定义的路径(/srun3/etc/srun.conf 和 /srun3/etc/system.conf)读取配置文件。 但是,如果你使用 GetConfig("common/conf") 设置了不同的配置文件路径,该包将使用指定的路径。

读取配置

要获取配置,使用 config.GetConfig("") 函数:

config, err := config.GetConfig("")
if err != nil {
fmt.Printf("获取配置失败:%v\n", err)
return
}

GetConfig() 函数将返回一个 Config 结构体,其中包含加载的配置。

访问配置

一旦获得 Config 结构体,可以使用点符号访问各个配置值。例如:

fmt.Println("Srun 用户名:", config.SrunConfig.Username)
fmt.Println("System 在线服务器:", config.SystemConfig.OnlineServer)

示例

以下是使用 Config 包的示例代码:

package main

import (
"fmt"

    "github.com/Eros-Vertigo/srun4-config"
)

func main() {
// 设置配置文件目录路径
    // 获取配置
    config, err := config.GetConfig("")
    if err != nil {
        fmt.Printf("获取配置失败:%v\n", err)
        return
    }

    // 访问各个配置
    fmt.Println("Srun 用户名:", config.SrunConfig.Username)
    fmt.Println("System 在线服务器:", config.SystemConfig.OnlineServer)
}

srun4-config's People

Contributors

dot-xiaoyuan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.