ran gofmt
This commit is contained in:
parent
d5fc3d8d23
commit
da14c059c1
5 changed files with 219 additions and 204 deletions
6
api.go
6
api.go
|
@ -1,18 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
//"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/ggicci/httpin"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const DEFAULT_RESULT_COUNT = 50;
|
||||
const DEFAULT_RESULT_COUNT = 50
|
||||
|
||||
type GetTransactionPaginationInput struct {
|
||||
ResultCount int `in:"query=result_count"`
|
||||
|
|
18
db.go
18
db.go
|
@ -3,13 +3,13 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"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)
|
||||
if err != nil {
|
||||
log.Fatal().
|
||||
|
@ -20,18 +20,18 @@ func db_get_transactions(transactions *[]Transaction,r *GetTransactionPagination
|
|||
defer db.Close()
|
||||
|
||||
err = db.Select(transactions,
|
||||
"SELECT trns_id, trns_amount, trns_description, " +
|
||||
"trns_account, trns_bucket, trns_date " +
|
||||
fmt.Sprintf("FROM %stransactions ORDER BY trns_id DESC ", DB_SCHEMA) +
|
||||
"SELECT trns_id, trns_amount, trns_description, "+
|
||||
"trns_account, trns_bucket, trns_date "+
|
||||
fmt.Sprintf("FROM %stransactions ORDER BY trns_id DESC ", DB_SCHEMA)+
|
||||
fmt.Sprintf("LIMIT %d OFFSET %d",
|
||||
r.ResultCount, r.PageNum * r.ResultCount ))
|
||||
r.ResultCount, r.PageNum*r.ResultCount))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
log.Info()
|
||||
|
@ -45,8 +45,8 @@ func db_new_transaction(transaction Transaction) (error) {
|
|||
log.Debug().Msgf("%#v", transaction)
|
||||
|
||||
_, err = db.NamedExec(
|
||||
fmt.Sprintf("INSERT INTO %stransactions", DB_SCHEMA) +
|
||||
"(trns_amount, trns_description, trns_account, trns_bucket, trns_date)" +
|
||||
fmt.Sprintf("INSERT INTO %stransactions", DB_SCHEMA)+
|
||||
"(trns_amount, trns_description, trns_account, trns_bucket, trns_date)"+
|
||||
"VALUES (:trns_amount, :trns_description, :trns_account, :trns_bucket, :trns_date)",
|
||||
transaction)
|
||||
if err != nil {
|
||||
|
|
4
main.go
4
main.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"nickiel.net/recount_server/tests"
|
||||
"nickiel.net/recount_server/web"
|
||||
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
@ -71,7 +72,6 @@ func main() {
|
|||
debug_mode.Init_testdb(DB_TYPE, DB_CONNECTION_STRING)
|
||||
}
|
||||
|
||||
|
||||
debug_mode.SetLogLevel(zerolog.GlobalLevel())
|
||||
|
||||
log.Info().Msg("starting server")
|
||||
|
@ -89,8 +89,8 @@ func main() {
|
|||
// processing should be stopped.
|
||||
//r.Use(middleware.Timeout(60 * time.Second))
|
||||
|
||||
r.Get("/", hello)
|
||||
r.Get("/headers", headers)
|
||||
r.Mount("/", web.WebRouter())
|
||||
r.Mount("/api", apiRouter())
|
||||
|
||||
err := http.ListenAndServe(":8090", r)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package debug_mode
|
||||
|
||||
import (
|
||||
"os"
|
||||
"encoding/json"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
@ -149,13 +149,11 @@ INSERT INTO transactions (trns_amount, trns_description, trns_account, trns_buck
|
|||
log.Fatal().Err(err).Msg("could not unmarshal")
|
||||
}
|
||||
|
||||
_, err = db.NamedExec("INSERT INTO transactions" +
|
||||
"(trns_amount, trns_description, trns_account, trns_bucket, trns_date)" +
|
||||
_, err = db.NamedExec("INSERT INTO transactions"+
|
||||
"(trns_amount, trns_description, trns_account, trns_bucket, trns_date)"+
|
||||
"VALUES (:trns_amount, :trns_description, :trns_account, :trns_bucket, :trns_date)",
|
||||
trns)
|
||||
|
||||
|
||||
|
||||
log.Debug().Msg("Test database initialized")
|
||||
|
||||
}
|
||||
|
|
17
web/router.go
Normal file
17
web/router.go
Normal 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) {
|
||||
|
||||
}
|
Loading…
Reference in a new issue