company facts simple read out of xls works

This commit is contained in:
Andreas Schröpfer
2021-02-28 08:33:00 +01:00
parent e0faa1fc7c
commit 90af0db862
11 changed files with 197 additions and 170 deletions

View File

@@ -1,10 +1,28 @@
package loader
import (
"bytes"
_ "embed"
"encoding/json"
"io"
"log"
)
//go:embed conf/default.json
var defaultConf []byte
// DefaultConf loads the defaultConf of the package. The base
// is the default.json inside the package definition.
func DefaultConf() *Conf {
buf := bytes.NewBuffer(defaultConf)
conf := &Conf{}
err := conf.DecodeJSON(buf)
if err != nil {
log.Println("cannot decode default conf: ", err)
}
return conf
}
// Conf configures the mapping from the excel version
// to the eCalc structure
type Conf struct {
@@ -15,6 +33,20 @@ type Conf struct {
Rating Rating `json:"rating"`
}
// EncodeJSON writes the JSON of the conf into the Writer
func (c Conf) EncodeJSON(w io.Writer) error {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
return enc.Encode(c)
}
// DecodeJSON writes the configuration from the reader into
// the pointer of the conf
func (c *Conf) DecodeJSON(r io.Reader) error {
dec := json.NewDecoder(r)
return dec.Decode(c)
}
// Value defines a single value inside the excel workbook
type Value struct {
Sheet int `json:"sheet"`
@@ -61,17 +93,3 @@ type Rating struct {
WeightCol string `json:"weight_col"`
SelectedByUserCol string `json:"selected_by_user_col"`
}
// EncodeJSON writes the JSON of the conf into the Writer
func (c Conf) EncodeJSON(w io.Writer) error {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
return enc.Encode(c)
}
// DecodeJSON writes the configuration from the reader into
// the pointer of the conf
func (c *Conf) DecodeJSON(r io.Reader) error {
dec := json.NewDecoder(r)
return dec.Decode(c)
}