This commit is contained in:
Albert Espín 2024-10-04 20:02:51 +02:00
parent 039f235d63
commit b579f53c57
14 changed files with 236 additions and 0 deletions

1
assets/css/bulma.css.map Normal file

File diff suppressed because one or more lines are too long

3
assets/css/bulma.min.css vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 761 B

BIN
assets/img/celsa.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

2
assets/js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

75
cmd/app.go Normal file
View File

@ -0,0 +1,75 @@
package cmd
import (
"flag"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"git.espin.casa/albert/cml04-falcon-ui/routes"
"git.espin.casa/albert/cml04-falcon-ui/storage"
"git.espin.casa/albert/logger"
"github.com/julienschmidt/httprouter"
)
func Run() error {
logLevel := flag.String("log-level", "debug", "trace log level")
httpAddr := flag.String("http-addr", ":3000", "http bind address")
// setup logger
log := logger.New(os.Stdout, *logLevel)
// log fields
logFields := logger.LogFields{
"http-bind": *httpAddr,
"log_level": *logLevel,
}
// create storage
storage := storage.New()
// create router
router := httprouter.New()
// create routes
routes.CreateRoutes(router, storage)
// serve static files
router.ServeFiles("/assets/*filepath", http.Dir("assets"))
// create http server
server := http.Server{
Addr: *httpAddr,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 5 * time.Second,
Handler: router,
}
// start the http server
go func() {
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}()
// info banner
log.Info("started Falcon UI", logFields)
// wait signal to finish
signal := WaitSignal()
log.Info("signal received", logFields.Add(logger.LogFields.Add(logFields, logger.LogFields{
"signal": signal,
})))
return nil
}
// WaitSignal catching exit signal
func WaitSignal() os.Signal {
ch := make(chan os.Signal, 2)
signal.Notify(
ch,
syscall.SIGINT,
syscall.SIGQUIT,
syscall.SIGTERM,
)
for {
sig := <-ch
switch sig {
case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM:
return sig
}
}
}

12
go.mod
View File

@ -1,3 +1,15 @@
module git.espin.casa/albert/cml04-falcon-ui
go 1.23.1
require (
git.espin.casa/albert/logger v1.0.0
github.com/julienschmidt/httprouter v1.3.0
)
require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

21
go.sum Normal file
View File

@ -0,0 +1,21 @@
git.espin.casa/albert/logger v1.0.0 h1:DF+SwwkptiZBiB1HUIPcKRRoLuUC7fVUfnF/I9p5Cj4=
git.espin.casa/albert/logger v1.0.0/go.mod h1:TXbZ7mayDtJvcs+DucVbs2klio9jq5k1eWFZ2wxgRGM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

19
handlers/index.go Normal file
View File

@ -0,0 +1,19 @@
package handlers
import (
"net/http"
"text/template"
"github.com/julienschmidt/httprouter"
)
func IndexHandler() httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
t, _ := template.ParseFiles("templates/index.html")
err := t.Execute(w, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}

9
main.go Normal file
View File

@ -0,0 +1,9 @@
package main
import "git.espin.casa/albert/cml04-falcon-ui/cmd"
func main() {
if err := cmd.Run(); err != nil {
panic(err)
}
}

12
routes/routes.go Normal file
View File

@ -0,0 +1,12 @@
package routes
import (
"git.espin.casa/albert/cml04-falcon-ui/handlers"
"git.espin.casa/albert/cml04-falcon-ui/storage"
"github.com/julienschmidt/httprouter"
)
func CreateRoutes(r *httprouter.Router, storage storage.Storager) {
r.GET("/", handlers.IndexHandler())
}

34
server/server.go Normal file
View File

@ -0,0 +1,34 @@
package server
import (
"net/http"
"time"
)
type Server struct {
Url string
}
func (s *Server) Start() error {
// Crear un servidor HTTP
server := http.Server{
Addr: s.Url,
ReadTimeout: 5 * time.Second, // time limit for reading
WriteTimeout: 5 * time.Second, // time limit for writting
IdleTimeout: 5 * time.Second,
}
// start api
go func() {
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}()
return nil
}
func New(url string) *Server {
return &Server{
Url: url,
}
}

9
storage/storage.go Normal file
View File

@ -0,0 +1,9 @@
package storage
type Storager interface{}
type storage struct{}
func New() Storager {
return &storage{}
}

39
templates/index.html Normal file
View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/assets/css/bulma.min.css">
<title>Falcon</title>
</head>
<body>
<div class="notification is-link">
<img src="/assets/img/celsa-resized.png" alt="celsa logo"> // FALCON
</div>
<div class="container is-fluid">
<aside class="menu">
<p class="menu-label">Código barras</p>
<ul class="menu-list">
<li><a>Consultas</a></li>
</ul>
<p class="menu-label">Paquetes</p>
<ul class="menu-list">
<li><a>Consultas</a></li>
</ul>
<p class="menu-label">Datos de fabricación</p>
<ul class="menu-list">
<li><a>Orden de producción</a></li>
<li><a>Orden de cliente</a></li>
<li><a>Hoja BCP</a></li>
</ul>
<p class="menu-label">Etiquetas</p>
<ul class="menu-list">
<li><a>Ultimas impresiones</a></li>
</ul>
</aside>
</div>
</body>
</html>