UPDATE imports
This commit is contained in:
parent
fb1036c1e7
commit
40dceb78c8
@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/maximotejeda/msvc-proto/golang/dolar"
|
"git.maximotejeda.com/maximo/dolar/proto/golang/dolar"
|
||||||
"github.com/maximotejeda/us_dop_api/domain"
|
"git.maximotejeda.com/maximo/us-dop-api/domain"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -8,12 +8,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/maximotejeda/us_dop_api/adapters/dolar"
|
"git.maximotejeda.com/maximo/us-dop-api/adapters/dolar"
|
||||||
"github.com/maximotejeda/us_dop_api/handlers"
|
"git.maximotejeda.com/maximo/us-dop-api/config"
|
||||||
"github.com/maximotejeda/us_dop_api/middlewares"
|
"git.maximotejeda.com/maximo/us-dop-api/handlers"
|
||||||
"github.com/maximotejeda/us_dop_api/static"
|
"git.maximotejeda.com/maximo/us-dop-api/middlewares"
|
||||||
"github.com/maximotejeda/us_dop_bot/config"
|
"git.maximotejeda.com/maximo/us-dop-api/static"
|
||||||
"github.com/maximotejeda/us_dop_db/db"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
)
|
)
|
||||||
@ -31,7 +31,7 @@ func main() {
|
|||||||
|
|
||||||
var opts []grpc.DialOption
|
var opts []grpc.DialOption
|
||||||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
dolarConn, err := grpc.Dial(config.GetDollarServiceURL(), opts...)
|
dolarConn, err := grpc.NewClient(config.GetDollarServiceURL(), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("creating gerpc conn", "error", err)
|
log.Error("creating gerpc conn", "error", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -60,10 +60,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// init database
|
// init database
|
||||||
dbe := db.Dial("dolardb/crawler.db", log)
|
|
||||||
|
|
||||||
// handler containing all the necessary files
|
// handler containing all the necessary files
|
||||||
root := handlers.NewRoot(dbe, dol, log, toParseFiles)
|
root := handlers.NewRoot( dol, log, toParseFiles)
|
||||||
|
|
||||||
s := middlewares.NewLogger(http.HandlerFunc(static.ServeFiles), log)
|
s := middlewares.NewLogger(http.HandlerFunc(static.ServeFiles), log)
|
||||||
r := middlewares.NewLogger(root, log)
|
r := middlewares.NewLogger(root, log)
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module github.com/maximotejeda/us_dop_api
|
module git.maximotejeda.com/maximo/us-dop-api
|
||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
|
|||||||
@ -6,14 +6,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/maximotejeda/us_dop_api/domain"
|
"git.maximotejeda.com/maximo/us-dop-api/domain"
|
||||||
"github.com/maximotejeda/us_dop_api/ports"
|
"git.maximotejeda.com/maximo/us-dop-api/ports"
|
||||||
"github.com/maximotejeda/us_dop_db/db"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
http.ServeMux
|
http.ServeMux
|
||||||
db *db.DB
|
|
||||||
dolar ports.DolarService
|
dolar ports.DolarService
|
||||||
log *slog.Logger
|
log *slog.Logger
|
||||||
templ template.Template
|
templ template.Template
|
||||||
@ -27,10 +26,9 @@ type SearchResult struct {
|
|||||||
Results []*domain.History `josn:"results"`
|
Results []*domain.History `josn:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApiHandler(db *db.DB, dolar ports.DolarService, log *slog.Logger, templ template.Template) *API {
|
func NewApiHandler( dolar ports.DolarService, log *slog.Logger, templ template.Template) *API {
|
||||||
log = log.With("api", "insti")
|
log = log.With("api", "insti")
|
||||||
api := &API{
|
api := &API{
|
||||||
db: db,
|
|
||||||
log: log,
|
log: log,
|
||||||
dolar: dolar,
|
dolar: dolar,
|
||||||
templ: templ,
|
templ: templ,
|
||||||
|
|||||||
@ -9,8 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/maximotejeda/us_dop_api/domain"
|
"git.maximotejeda.com/maximo/us-dop-api/domain"
|
||||||
"github.com/maximotejeda/us_dop_api/helpers"
|
"git.maximotejeda.com/maximo/us-dop-api/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// handler to parse query to the api
|
// handler to parse query to the api
|
||||||
|
|||||||
@ -7,9 +7,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/maximotejeda/us_dop_api/handlers/api"
|
"git.maximotejeda.com/maximo/us-dop-api/handlers/api"
|
||||||
"github.com/maximotejeda/us_dop_api/ports"
|
"git.maximotejeda.com/maximo/us-dop-api/ports"
|
||||||
"github.com/maximotejeda/us_dop_db/db"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -19,13 +18,12 @@ var (
|
|||||||
// Mux will mix and match all sub routes
|
// Mux will mix and match all sub routes
|
||||||
type Root struct {
|
type Root struct {
|
||||||
http.ServeMux
|
http.ServeMux
|
||||||
db *db.DB
|
|
||||||
log *slog.Logger
|
log *slog.Logger
|
||||||
dolar ports.DolarService
|
dolar ports.DolarService
|
||||||
templates *template.Template
|
templates *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoot(dbe *db.DB, dolar ports.DolarService, log *slog.Logger, files []string) *Root {
|
func NewRoot(dolar ports.DolarService, log *slog.Logger, files []string) *Root {
|
||||||
funcMap := template.FuncMap{
|
funcMap := template.FuncMap{
|
||||||
"add": add[float64],
|
"add": add[float64],
|
||||||
"div": div,
|
"div": div,
|
||||||
@ -44,7 +42,7 @@ func NewRoot(dbe *db.DB, dolar ports.DolarService, log *slog.Logger, files []str
|
|||||||
templ.ExecuteTemplate(w, "index", nil)
|
templ.ExecuteTemplate(w, "index", nil)
|
||||||
//w.Write([]byte("{'status': 'ok'}"))
|
//w.Write([]byte("{'status': 'ok'}"))
|
||||||
})
|
})
|
||||||
inst := api.NewApiHandler(dbe, dolar, log, templ)
|
inst := api.NewApiHandler( dolar, log, templ)
|
||||||
r.Handle("GET /api/{inst}/", inst)
|
r.Handle("GET /api/{inst}/", inst)
|
||||||
r.Handle("POST /api/instituciones/history", inst)
|
r.Handle("POST /api/instituciones/history", inst)
|
||||||
r.Handle("GET /api/latest/{inst}", inst)
|
r.Handle("GET /api/latest/{inst}", inst)
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package ports
|
package ports
|
||||||
|
|
||||||
import "github.com/maximotejeda/us_dop_api/domain"
|
import "git.maximotejeda.com/maximo/us-dop-api/domain"
|
||||||
|
|
||||||
type DolarService interface {
|
type DolarService interface {
|
||||||
GetLatest(name string) (*domain.History, error)
|
GetLatest(name string) (*domain.History, error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user