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