Go Configure – Josh Betz https://josh.blog/2017/04/go-configure

Go Configure

APRIL 27, 2017 #

I’ve been dabbling in Golang on and off for a little while now. Recently I was looking for a package to read and parse configuration files with the following requirements in mind:

  1. Be fast.
  2. Use environment variables and JSON files (in that order).
  3. Support hot reloading.

I looked at some of the popular configuration packages, but didn’t see anything that I loved. Many of them don’t meet the requirements I had in mind or are more complex than I’d like.

So, I decided to write config — I know, it’s a great name. It’s pretty simple. We cache values in memory to minimize disk IO. On SIGHUP (or any time you call config.Reload()), we clear the cache, so you can update the configuration without restarting your app.

Usage looks something like this:

 

There are more examples and details on the API in the README on Github.

If you have questions or ideas, issues and pull requests are welcome on Github. Let me know if you use it!

package main

import (
"fmt"
"log"
"net/http" "github.com/joshbetz/config"
) func main() {
c := config.New("config.json") http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var value string
err := c.Get("value", &value) if err != nil {
fmt.Fprintf(w, "Error: %s\n", err)
return
} fmt.Fprintf(w, "Value: %s\n", value)
}) log.Fatal(http.ListenAndServe(":3000", nil))
}

  

Go Configure Support hot reloading.的更多相关文章

  1. Webpack vs Browersify vs SystemJs for SPAs

    https://engineering.velocityapp.com/webpack-vs-browersify-vs-systemjs-for-spas-95b349a41fa0 Right no ...

  2. 构建通用的 React 和 Node 应用

    这是一篇非常优秀的 React 教程,这篇文章对 React 组件.React Router 以及 Node 做了很好的梳理.我是 9 月份读的该文章,当时跟着教程做了一遍,收获很大.但是由于时间原因 ...

  3. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q4-Q5)

    Question 4 You are designing a SharePoint 2010 application to store 50 GB of digital assets, includi ...

  4. Canu Parameter Reference(canu参数介绍)

    链接:Canu Parameter Reference To get the most up-to-date options, run canu -options The default values ...

  5. [React + webpack] hjs-webpack

    You can easily spend hours configuring the perfect dev environment with all the latest hotness like ...

  6. UE4读取脑电波MindWave插件(展示如何使用第三方库制作UE4插件)

    MyEEGPlugin.uplugin { , , "VersionName": "1.0", "FriendlyName": " ...

  7. UE4修改自Rama的UDP通信蓝图插件

    UE4.15没有提供蓝图UDP的组件,可以在网上找到一个ID叫Rama写的源代码,我把它封装成插件了(MyUdpPlugin),方便在各个UE4版本工程中使用UDP通信. 使用方式: 1.在自己的工程 ...

  8. (原)Unreal源码搬山-动画篇 自定义动画节点(一)

    @author:黑袍小道 太忙了,来更新下,嘿嘿 前言: 本文是接着上文 Unreal搬山之动画模块_Unreal动画流程和框架,进行简单入门如何自定义动画图标的AnimNode. 正文: 一.Ani ...

  9. uboot的readme

    ## (C) Copyright 2000 - 2008# Wolfgang Denk, DENX Software Engineering, wd@denx.de.## See file CREDI ...

随机推荐

  1. javascript中call、apply、argument、callee、caller

    1.Call方法 调用一个对象的一个方法,以另一个对象替换当前对象. call([thisObj[,arg1[, arg2[, [,.argN]]]]]) thisObj 可选项.将被用作当前对象的对 ...

  2. MPC8313ERDB在Linux从NAND FLASH读取UBoot环境变量的代码分析

    MPC8313ERDB在Linux从NAND FLASH读取UBoot环境变量的代码分析 Yao.GUET@2014-05-19 一.故事起因 由于文件系统的增大,已经大大的超出了8MB的NOR FL ...

  3. 解决 openpyxl 垂直分页符和水平分页符同时添加的问题

    前言 十天前知乎上有人提问 python:openpyxl模块怎么给表格添加分页符?实现分页打印功能?,看到问题之后,我很快的给他了一个如何添加垂直分页符或水平分页符的示例,你以为问题就结束了?我是这 ...

  4. C语言中,为什么字符串可以赋值给字符指针变量

    转载于:http://www.cnblogs.com/KingOfFreedom/archive/2012/12/07/2807223.html 本文是通过几篇转帖的文章整理而成的,内容稍有修改: 一 ...

  5. CSS之少用继承,多用组合

    下面是一段普通的代码: css: .box{ border:1px solid #ccc; font-size:12px; background:#f1f1f1; padding:10px; } ht ...

  6. CS文件类头注释

    1.修改unity生成CS文件的模板(模板位置:Unity\Editor\Data\Resources\ScriptTemplates 文件名:81-C# Script-NewBehaviourScr ...

  7. 在工程名.h头文件中写public:

    class CaccessimageApp : public CWinApp { public: _ConnectionPtr m_pConnection; CaccessimageApp(); // ...

  8. linux环境中,nginx安装过程

    需求描述: 记录在linux平台,nginx安装的过程. 环境描述: 操作系统:Red Hat Enterprise Linux Server release 6.6 (Santiago) 操作内核版 ...

  9. Extjs 自定义控件

    // JavaScript Document Ext.namespace('CRM.Panels'); CRM.Panels.UserDetail = Ext.extend(Ext.Panel,{ w ...

  10. Sencha Cmd创建Ext JS示例项目

    Sencha提供了免费的Cmd工具,可以用来创建Ext JS项目并提供了一些便利的功能. Sencha也在官方文档中提供了一个示例来演示如何创建一个Sample Login App. 本文就介绍一下这 ...