-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Template better and make length/expire configurable (#44)
* Templating all html files and adding configuration for max length, max ui length, and max expire
- Loading branch information
Showing
17 changed files
with
262 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kelseyhightower/envconfig" | ||
) | ||
|
||
type specification struct { | ||
Port int `default:"5000" envconfig:"PORT"` | ||
RedisUrl string `default:"redis://localhost:6379" envconfig:"REDIS_URL"` | ||
EnableHsts bool `split_words:"true"` | ||
Port int `default:"5000" envconfig:"PORT"` | ||
RedisUrl string `default:"redis://localhost:6379" envconfig:"REDIS_URL"` | ||
EnableHsts bool `split_words:"true"` | ||
MaxLength int `default:"1000" split_words:"true"` | ||
UiMaxLength int `default:"512" split_words:"true"` | ||
MaxExpire int `default:"24" split_words:"true"` | ||
} | ||
|
||
var Config specification | ||
|
||
func GetConfig() error { | ||
return envconfig.Process("tmpnotes", &Config) | ||
err := envconfig.Process("tmpnotes", &Config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if Config.UiMaxLength > Config.MaxLength { | ||
return fmt.Errorf("UiMaxLength %v should not be greater than MaxLength %v", Config.UiMaxLength, Config.MaxLength) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
import ( | ||
"html/template" | ||
) | ||
|
||
var ( | ||
Tmpl *template.Template | ||
err error | ||
path = "templates/*" | ||
) | ||
|
||
func GetTemplates() error { | ||
Tmpl, err = template.ParseGlob(path) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package config | ||
|
||
import "testing" | ||
|
||
func TestGetTemplates(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
wantErr bool | ||
path string | ||
}{ | ||
{ | ||
name: "Test 1", | ||
wantErr: false, | ||
path: "../../templates/*", | ||
}, | ||
{ | ||
name: "Test 2", | ||
wantErr: true, | ||
path: "../../test_data/bad_templates/*", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
path = tt.path | ||
if err := GetTemplates(); (err != nil) != tt.wantErr { | ||
t.Errorf("GetTemplates() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.