ran gofmt

This commit is contained in:
Nickiel12 2024-01-11 20:07:47 -08:00
parent d5fc3d8d23
commit da14c059c1
5 changed files with 219 additions and 204 deletions

6
api.go
View file

@ -1,18 +1,18 @@
package main package main
import ( import (
"net/http"
"encoding/json" "encoding/json"
"net/http"
//"context" //"context"
"fmt" "fmt"
"github.com/go-chi/chi/v5"
"github.com/ggicci/httpin" "github.com/ggicci/httpin"
"github.com/go-chi/chi/v5"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
const DEFAULT_RESULT_COUNT = 50; const DEFAULT_RESULT_COUNT = 50
type GetTransactionPaginationInput struct { type GetTransactionPaginationInput struct {
ResultCount int `in:"query=result_count"` ResultCount int `in:"query=result_count"`

6
db.go
View file

@ -3,13 +3,13 @@ package main
import ( import (
"fmt" "fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq" _ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
func db_get_transactions(transactions *[]Transaction,r *GetTransactionPaginationInput) (error) { func db_get_transactions(transactions *[]Transaction, r *GetTransactionPaginationInput) error {
db, err := sqlx.Connect(DB_TYPE, DB_CONNECTION_STRING) db, err := sqlx.Connect(DB_TYPE, DB_CONNECTION_STRING)
if err != nil { if err != nil {
log.Fatal(). log.Fatal().
@ -31,7 +31,7 @@ func db_get_transactions(transactions *[]Transaction,r *GetTransactionPagination
return nil return nil
} }
func db_new_transaction(transaction Transaction) (error) { func db_new_transaction(transaction Transaction) error {
db, err := sqlx.Connect(DB_TYPE, DB_CONNECTION_STRING) db, err := sqlx.Connect(DB_TYPE, DB_CONNECTION_STRING)
if err != nil { if err != nil {
log.Info() log.Info()

View file

@ -2,6 +2,7 @@ package main
import ( import (
"nickiel.net/recount_server/tests" "nickiel.net/recount_server/tests"
"nickiel.net/recount_server/web"
"database/sql" "database/sql"
"net/http" "net/http"
@ -71,7 +72,6 @@ func main() {
debug_mode.Init_testdb(DB_TYPE, DB_CONNECTION_STRING) debug_mode.Init_testdb(DB_TYPE, DB_CONNECTION_STRING)
} }
debug_mode.SetLogLevel(zerolog.GlobalLevel()) debug_mode.SetLogLevel(zerolog.GlobalLevel())
log.Info().Msg("starting server") log.Info().Msg("starting server")
@ -89,8 +89,8 @@ func main() {
// processing should be stopped. // processing should be stopped.
//r.Use(middleware.Timeout(60 * time.Second)) //r.Use(middleware.Timeout(60 * time.Second))
r.Get("/", hello)
r.Get("/headers", headers) r.Get("/headers", headers)
r.Mount("/", web.WebRouter())
r.Mount("/api", apiRouter()) r.Mount("/api", apiRouter())
err := http.ListenAndServe(":8090", r) err := http.ListenAndServe(":8090", r)

View file

@ -1,9 +1,9 @@
package debug_mode package debug_mode
import ( import (
"os"
"encoding/json"
"database/sql" "database/sql"
"encoding/json"
"os"
"time" "time"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
@ -154,8 +154,6 @@ INSERT INTO transactions (trns_amount, trns_description, trns_account, trns_buck
"VALUES (:trns_amount, :trns_description, :trns_account, :trns_bucket, :trns_date)", "VALUES (:trns_amount, :trns_description, :trns_account, :trns_bucket, :trns_date)",
trns) trns)
log.Debug().Msg("Test database initialized") log.Debug().Msg("Test database initialized")
} }

17
web/router.go Normal file
View file

@ -0,0 +1,17 @@
package web
import (
"net/http"
"github.com/go-chi/chi/v5"
)
func WebRouter() http.Handler {
r := chi.NewRouter()
r.Get("/", getIndex)
return r
}
func getIndex(w http.ResponseWriter, req *http.Request) {
}