Skip to content

Releases: kambahr/go-webconfig

New: Commented JSON config - inline comments

22 Jan 06:34
Compare
Choose a tag to compare

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

22 Jan 00:02
Compare
Choose a tag to compare

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

01 Jan 22:46
Compare
Choose a tag to compare

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

30 Dec 00:29
Compare
Choose a tag to compare
  • 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

30 Sep 11:44
Compare
Choose a tag to compare

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

14 Sep 10:58
Compare
Choose a tag to compare

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

01 Aug 12:24
Compare
Choose a tag to compare

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

26 Jul 23:38
Compare
Choose a tag to compare

Fixed bug - Data section

Multi-spaces between key and value was causing the line to be skipped.

Added a section for arbitrary data

05 Jun 13:05
e26291c
Compare
Choose a tag to compare

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

v1.0.2

04 Jun 16:39
Compare
Choose a tag to compare

Config file vars

  • Added a new section: Site
    • Moved general website info (hostname, portno, proto) under Site section.
  • Added portno to Admin section.
  • Added json strings the Config type.

Fixed

same-name different-section wasn't working.