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 ...
随机推荐
- 【c语言】推断一个数是奇偶数
// 推断一个数是奇偶数 #include <stdio.h> void judge_sd(int a) { if ((a & 1) == 0) { printf("是偶 ...
- 如何研究某个gene的ceRNA 网络
研究人员针对 PTEN 这个关键的抑癌基因,来探究调控该基因表达的ceRNA 网络: 分析策略: 1)预测能调控该基因的miRNAs 通过miRanda 软件预测和实验验证相结合的方式,挑选出 miR ...
- openal资料转贴
地址:http://blog.sina.com.cn/s/blog_685b5b220100ukbp.html OpenAL简介 OpenAL(Open Audio Library)是专门负责3D定位 ...
- c++ const enum #define
最后的最后,我们略微总结一下: 1.只是声明单一固定值,尽可能采用const. 2.如果是一组固定值,并且互相有关联,则采用enum. 3.不涉及条件编译,只 ...
- SPP-Net
R-CNN -> SPP-Net -> Fast-RCNN
- 【转】Internet与Intranet区别
提起Internet,大家都知道它是一个蓬勃发展的国际互联网. 而Intranet则是近两年才发展起来的新事物,通常被称作企业内部网. Internet是一组全球范围内信息资源的名字.这些资源非常巨大 ...
- implode,explode的使用
implode把数组转成字符串的函数,在组合SQL语句时候使用特好使! 比如 $a = array('a','b','c');$b = implode(',', $a);echo $b; 返回的字符串 ...
- testNG框架提示:Cannot find class in classpath: NewTest
selenium+Java的testNG运行时,报如下错误: org.testng.TestNGException: Cannot find class in classpath: NewTest a ...
- shell基础(八)-循环语句
国庆过后:感觉有点慵懒些了:接着上篇:我们继续来学习循环语句. 一. for循环 与其他编程语言类似,Shell支持for循环. for循环一般格式为: for 变量 in 列表 do command ...
- ZooKeeper(七)-- ZK原生API实现分布式锁
一.使用场景 在分布式应用,往往存在多个进程提供同一服务.这些进程有可能在相同的机器上,也有可能分布在不同的机器上. 如果这些进程共享了一些资源,可能就需要分布式锁来锁定对这些资源的访问. 二.实现分 ...