Go Configure Support hot reloading.
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:
- Be fast.
- Use environment variables and JSON files (in that order).
- 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.的更多相关文章
- Webpack vs Browersify vs SystemJs for SPAs
https://engineering.velocityapp.com/webpack-vs-browersify-vs-systemjs-for-spas-95b349a41fa0 Right no ...
- 构建通用的 React 和 Node 应用
这是一篇非常优秀的 React 教程,这篇文章对 React 组件.React Router 以及 Node 做了很好的梳理.我是 9 月份读的该文章,当时跟着教程做了一遍,收获很大.但是由于时间原因 ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q4-Q5)
Question 4 You are designing a SharePoint 2010 application to store 50 GB of digital assets, includi ...
- Canu Parameter Reference(canu参数介绍)
链接:Canu Parameter Reference To get the most up-to-date options, run canu -options The default values ...
- [React + webpack] hjs-webpack
You can easily spend hours configuring the perfect dev environment with all the latest hotness like ...
- UE4读取脑电波MindWave插件(展示如何使用第三方库制作UE4插件)
MyEEGPlugin.uplugin { , , "VersionName": "1.0", "FriendlyName": " ...
- UE4修改自Rama的UDP通信蓝图插件
UE4.15没有提供蓝图UDP的组件,可以在网上找到一个ID叫Rama写的源代码,我把它封装成插件了(MyUdpPlugin),方便在各个UE4版本工程中使用UDP通信. 使用方式: 1.在自己的工程 ...
- (原)Unreal源码搬山-动画篇 自定义动画节点(一)
@author:黑袍小道 太忙了,来更新下,嘿嘿 前言: 本文是接着上文 Unreal搬山之动画模块_Unreal动画流程和框架,进行简单入门如何自定义动画图标的AnimNode. 正文: 一.Ani ...
- uboot的readme
## (C) Copyright 2000 - 2008# Wolfgang Denk, DENX Software Engineering, wd@denx.de.## See file CREDI ...
随机推荐
- 天线增益英文名称:antenna gain
天线增益是指:在输入功率相等的条件下,实际天线与理想的辐射单元在空间同一点处所产生的信号的功率密度之比.它定量地描述一个天线把输入功率集中辐射的程度.增益显然与天线方向图有密切的关系,方向图主瓣越窄, ...
- JavaSE(八)之Collection总结
前面几篇把集合中的知识大概都详细的说了一遍,但是我觉得还是要总结一下,这样的话,可以更好的理解集合. 一.Collection接口 首先我们要一张图来说明: Collection接口,它是集合的顶层接 ...
- c++ list sort
1. bool operator < (S & b) { return ID < b.ID; } struct S { std::string firstn ...
- List<T>与ObservableCollectio<T> 的区别
在WPF中绑定通常会使用ObservableCollection,为什么不使用List呢? 简单是解释:List不包含值变通知功能,所以绑定了也许会出现绑定的数据与呈现数据不一致的问题. 通常绑定会使 ...
- Swift - UITableView的用法
因为倾向于纯代码编码,所以不太喜欢可视化编程,不过也略有研究,所以项目里面的所有界面效果,全部都是纯代码编写! 终于到了重中之重的tableview的学习了,自我学习ios编程以来,工作中用得最多的就 ...
- java 字符编码问题
编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串.但是要保证汉字不被截半个,如“我ABC”4,应该截为“我AB”,输入“我ABC汉DEF”,6,应该输出为“我ABC”而不是 ...
- Linux wc 命令
wc命令可以用来统计文件的行数 .单词数 .字符数,用法如下: [root@localhost ~]$ wc 1.txt # 统计文件的行数.单词数.字符数 2 4 24 1.txt [root@lo ...
- Swift-属性、方法、下标
存储属性和计算属性 类.结构和枚举都能够定义存储属性和计算属性.其中存储属性就是常见的形式,又分为变量属性和常量属性,如: struct Point { var x = 0.0, y = 0.0 } ...
- CSS3 Transform变形(2D转换)
Transform:对元素进行变形:Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开始,结束.Animation:对元素某个属性 ...
- Mahout实现基于用户的协同过滤算法
Mahout中对协同过滤算法进行了封装,看一个简单的基于用户的协同过滤算法. 基于用户:通过用户对物品的偏好程度来计算出用户的在喜好上的近邻,从而根据近邻的喜好推测出用户的喜好并推荐. 图片来源 程序 ...