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. javaEE mvc样例具体解释

    一个不错的样例值得细细品味: 以下依照包顺序将代码贴出来供大家參考: IEmpDAO package org.lzch.dao; import java.util.List; import org.l ...

  2. NGUI与EasyTouch结合使用

    用了EasyTouch插件一段时间了,小问题还是有一些,总体来说用起来还行.这篇文章我就来说说EasyTouch和NGUI的结合. 总体来说触摸屏幕也就三种情况. 1.触摸事件只响应NGUI部分,不响 ...

  3. OpenCV学习:OpenCV文件一览

    了解一些OpenCV代码整体的模块结构后,再重点学习自己感兴趣的部分,会有一种一览众山小的感觉~ Come on! C:\OpenCV\opencv\build\include文件夹下包含两个文件夹: ...

  4. day25<多线程+&设计模式&GUI>

    多线程(单例设计模式)(掌握) 多线程(Runtime类) 多线程(Timer)(掌握) 多线程(两个线程间的通信)(掌握) 多线程(三个或三个以上间的线程通信) 多线程(线程间的通信注意的问题) 多 ...

  5. swift - UISegmentedControl 的用法

    一.创建控件,并监听控件选择值 /*选项除了文字还可以是图片 as关键字的作用就是字面意思:类型转换*/ let items = ["选项一", "选项二", ...

  6. grep递归查找子目录

    想要在各种文件里面找一个指定的文本,本来的方法太土了,在网上搜了一下,发现个好的方法,不过也有些问题.原文如下: 第一个,这个是看别人脚本的,配合find实现,-maxdepth指定深度,如果查找到底 ...

  7. Serlvet学习笔记之一 ——实现servlet的3种方法

    1.配置环境,从tomcat的lib下面引入servlet-api.jar包.

  8. U3D关于message的使用

    Message相关有3条指令: SendMessage ("函数名",参数,SendMessageOptions) //GameObject自身的Script BroadcastM ...

  9. IP地址转、整数互相转换

    知识点:一个二进制数,按位左移n位,就是把该数的值乘以2的n次方                  二进制除二即右移一位 1.IP地址转换为整数 原理:IP地址每段可以看成是8位无符号整数即0-255 ...

  10. ajax的历史

    ajax (AJAX开发) 编辑 AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX ...