Using the configuration to access some values
This commit is contained in:
@@ -0,0 +1 @@
|
||||
build/
|
||||
+3
-2
@@ -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
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
use: "network"
|
||||
network:
|
||||
host: "127.0.0.1"
|
||||
port: "9099"
|
||||
usb:
|
||||
path: "/dev/usb/lp0"
|
||||
|
||||
dbpath: "./data.db"
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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=
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user