Releases: kambahr/go-webconfig
New: Commented JSON config - inline comments
Commented JSON config
Use comment lines using # at the beginning of each line, within a line ; and /* */ blocks
anywhere in the json block.
func LoadJSONConfig(path string) (map[string]interface{}, []byte)
# Top notes
# some more text...
{
# more notes...
"my-info":
[
# notes for object one
{
# my comments...
"some-key" : "some value /* notes go here */",
# notes for this key
"some-array" :
[
"value 1", # inline comment will also be omitted
/* more notes */
"value 2"
]
}
]
}
New: Load Commented JSON Config file
Commented JSON config
Use comment lines using # at the begining of each line; and /* */ blocks
anywhere in the json block.
func LoadJSONConfig(path string) (map[string]interface{}, []byte)
# Top notes
# some more text...
{
# more notes...
"my-info":
[
# notes for object one
{
# my comments...
"some-key" : "some value /* notes go here */",
# notes for this key
"some-array" :
[
"value 1",
/* more notes */
"value 2"
]
}
]
}
Fixed: ValidateHTTPRequest() rejecting local ip addr 127.0.0.1
ValidateHTTPRequest() was rejecting request if host was 127.0.0.1.
Default allowed hosts should be localhost, 127.0.0.1 and a per-defined one:
// Host name
rHost := strings.ToLower(strings.Split(r.Host, ":")[0])
if c.Site.HostName != "" && rHost != c.Site.HostName && rHost != "localhost" && rHost != "127.0.0.1" {
return false, http.StatusBadGateway
}
New: HTTP Request Validation and Conditional HTTP Service
- Conditional HTTP Service based on ip address, header, and query string.
The following example allows only bing and google bots to see /robot.txt:
conditional-http-service [{"rule-type":"ip-address","url-path":"/robot.txt","serve-only-to-criteria":["+http://www.bing.com/bingbot.htm","+http://www.google.com/bot.html"],"http-status-code":404}]]
See ConditionalHTTPService and conditional-http-service in defs.go
- Built-in Request Validation; usage example:
isRequestValid, httpErrCode := Config.ValidateHTTPRequest(w, r)
if httpErrCode == http.StatusTemporaryRedirect || httpErrCode == http.StatusBadGateway {
return
} else {
// deal with the request according to the http error code
}
Fixed - empty lines added on save
Fixed - empty lines added on save
When UpdateConfigValue() was called, extra lines were being added to the appdata/.cfg/.all file... making the file larger disproportionately; compared to its content.
The save operation will now leave only one blank line and removes all redundant ones before writing to disk.
Fixed - section on first line
Fixed - section on first line
When section was on the very first line, it was skipped (taken as a key).
Fixed - too many open file error
Fixed - too many open file error
The config file is opened for read every few seconds... the original
Go ReadFile() func (../src/os/file.go) closes the file on defer; and since the refreshConfig()
loops inside itself via goto, the file.Close() is never called,
hence the too may open file error. The ReadFile() func in util.go is the same
Go ReadFile() func with the exception of closing the file before
return.
Fixed bug - Data section
Fixed bug - Data section
Multi-spaces between key and value was causing the line to be skipped.
Added a section for arbitrary data
Added the Data section
This Data section is a map[string]string in the Config type that holds user-data. The following is the format.
Key...... no spaces
Value.... can include spaces.
- Data-value can be any text (hex, JSON, text, xml,..).
- Delimiter is a new-line.
Example:
Data
my-postgresql-conn-str User ID=root;Password=pwd;Host=localhost;Port=5432;Database=mydb;Pooling=false;
# comments can here inserted in between rows.
my-json-value {"mylist":["v1","v2"]} my-hex-value 68656c6c6f206f75742074686572652e206775697461722069732074686520736f6e67