diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/src/Makefile b/src/Makefile index 1984446..4fb747e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,8 +2,9 @@ build: clean mkdir build go build -o build/frontend cp -r ./assets build - touch build/data.db - sqlite3 build/data.db < ./usefulQueries.sql + # cp ./config.yml build/config.yml + # touch build/data.db + # sqlite3 build/data.db < ./usefulQueries.sql clean: rm -rf ./build diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..a7c0c1c --- /dev/null +++ b/src/config.yml @@ -0,0 +1,8 @@ +use: "network" +network: + host: "127.0.0.1" + port: "9099" +usb: + path: "/dev/usb/lp0" + +dbpath: "./data.db" \ No newline at end of file diff --git a/src/controllers/sendFax.go b/src/controllers/sendFax.go index d3534c6..09190e4 100644 --- a/src/controllers/sendFax.go +++ b/src/controllers/sendFax.go @@ -12,6 +12,7 @@ import ( "time" "unicode/utf8" + "thermalFax/config" "thermalFax/models" ) @@ -31,10 +32,12 @@ type WebFrontendResponse struct { // to print the message. // It should be able to send the requests both via http/https or sockets func sendRequestToPrinter(msg string) (PrintServerResponse, error) { + cfg := config.GetInstance("", nil) + // Send the request to the actual printer server req, err := http.NewRequest( http.MethodPost, - "http://127.0.0.1:9099/print", + "http://"+cfg.Network.Host+":"+cfg.Network.Port+"/print", bytes.NewBuffer([]byte(msg)), ) if err != nil { diff --git a/src/go.mod b/src/go.mod index a38c52a..bf673a6 100644 --- a/src/go.mod +++ b/src/go.mod @@ -4,6 +4,8 @@ go 1.22.2 require ( github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/google/go-cmp v0.6.0 github.com/mattn/go-sqlite3 v1.14.22 golang.org/x/crypto v0.22.0 + gopkg.in/yaml.v2 v2.4.0 ) diff --git a/src/go.sum b/src/go.sum index 839f752..ad1ad94 100644 --- a/src/go.sum +++ b/src/go.sum @@ -1,6 +1,12 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/src/main.go b/src/main.go index 132fd55..0bc222c 100644 --- a/src/main.go +++ b/src/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "thermalFax/config" "thermalFax/controllers" ) @@ -12,6 +13,9 @@ func checkMethod(method string, r *http.Request) bool { } func main() { + // Initialize configuration + _ = config.GetInstance("", nil) + // GET calls http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if !checkMethod(http.MethodGet, r) { diff --git a/src/models/authentication.go b/src/models/authentication.go index bbde6ce..362c1a5 100644 --- a/src/models/authentication.go +++ b/src/models/authentication.go @@ -4,6 +4,7 @@ import ( "log" "net/http" "strconv" + "thermalFax/config" "github.com/golang-jwt/jwt/v4" "golang.org/x/crypto/bcrypt" @@ -33,8 +34,10 @@ type SessionData struct { // Private functions func openDB() *Database { + cfg := config.GetInstance("", nil) + var d Database - err := d.Initialize("./data.db") + err := d.Initialize(cfg.DBPath) if err != nil { log.Fatal("Failed to get into DB: ", err) }