This commit is contained in:
tim
2017-09-07 01:44:30 +02:00
parent 201c69e414
commit 02b6ee7146
3 changed files with 186 additions and 147 deletions

View File

@@ -4,14 +4,10 @@ import (
"log"
"os"
"bitbucket.org/digitorus/pdfsign/sign"
"github.com/BurntSushi/toml"
"github.com/asaskevich/govalidator"
)
func init() {
govalidator.SetFieldsRequiredByDefault(true)
}
var (
DefaultLocation string = "./pdfsign.conf" // Default location of the config file
Settings Config // Initialized once inside Read method Settings are stored in memory.
@@ -19,24 +15,8 @@ var (
// Config is the root of the config
type Config struct {
//Info:
//Name: "Jeroen Bobbeldijk",
//Location: "Rotterdam",
//Reason: "Test",
//ContactInfo: "Geen",
//CertType: 2,
//Approval: false,
//TSA: sign.TSA{
//URL: "http://aatl-timestamp.globalsign.com/tsa/aohfewat2389535fnasgnlg5m23",
}
// ValidateFields validates all the fields of the config
func (c Config) ValidateFields() error {
_, err := govalidator.ValidateStruct(c)
if err != nil {
return err
}
return nil
Info sign.SignDataSignatureInfo
TSA sign.TSA
}
func Read(configfile string) {
@@ -50,9 +30,5 @@ func Read(configfile string) {
if _, err := toml.DecodeFile(configfile, &c); err != nil {
}
if err := c.ValidateFields(); err != nil {
log.Fatal("Config is not valid: ", err)
}
Settings = c
}

View File

@@ -20,18 +20,5 @@ staticPath = "../static"
}
// Root
assert.Equal(t, "../static", c.StaticPath)
}
func TestValidation(t *testing.T) {
const configContent = ``
var c config.Config
if _, err := toml.Decode(configContent, &c); err != nil {
t.Error(err)
}
err := c.ValidateFields()
assert.NotNil(t, err)
assert.Equal(t, "../static", c)
}