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 ...
随机推荐
- (38)JS运动之淡入淡出
基本思路:使用样式filter.可是要区分IE浏览器和chrom.firefox的不同,详细也是用定时器来实现. <!DOCTYPE HTML> <!-- --> <ht ...
- Python的类和函数的魔法
class CustomClass: def customFun(self, id): print("fun_1",id ) if __name__ == '__main__': ...
- Collapsing Margin:外边距叠加
参考:http://www.smallni.com/collapsing-margin/ http://www.cnblogs.com/v10258/p/3530290.html
- ulimit设置句柄数
这几天在做一个性能测试,写了一个模拟发送http的程序.模拟100并发的情况下,随机发http get的请求.放到服务器上运行一段时间抛出Too many open files的异常. 这几天在做一个 ...
- linux下mysql 启动命令
1,使用service 启动.关闭MySQL服务 service mysql start service mysql stop service mysql restart 运行上面命令,其实是serv ...
- 通过notepad++将混乱的xml配置的格式进行美化
需求描述: 最近在进行hbase配置文件的修改之后,发现xml文件的格式很不美观, 然后,在网上找了些方法,实测,通过notepad++的xml tools插件就可 达到美化效果. 操作过程: 1.以 ...
- 非常不错的前端框架Kendo-ui
近期公司在做重构,准备换前端框架由Extjs换kendo-ui,问什么要换框架呢?主要有以下几个原因: Extjs太重,偏向后端语言,前端写起来费劲 Extjs执行太慢(这是主要原因),因为Extjs ...
- opencv移植到ubuntu
原创博文,转载请标明出处--周学伟http://www.cnblogs.com/zxouxuewei/ OpenCV 2.2以后版本需要使用Cmake生成makefile文件,因此需要先安装cmake ...
- Linux,unix,cygwin,centeros下的tar压缩解压缩命令具体解释
tar Examples: tar -cf archive.tar foo bar # Create archive.tar from files foo and bar. tar -tvf ...
- Java精选笔记_Filter(过滤器)
Filter(过滤器) Filter入门 什么是Filter Filter被称作过滤器或者拦截器,其基本功能就是对Servlet容器调用Servlet的过程进行拦截,从而在Servlet进行响应处理前 ...