Not impl endpoints
parent
79600941be
commit
0b4ecd1916
|
|
@ -0,0 +1,23 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"local/args"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Port string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
New()
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() {
|
||||||
|
as := args.NewArgSet()
|
||||||
|
as.Append(args.INT, "p", "port to listen on", 52222)
|
||||||
|
if err := as.Parse(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
Port = fmt.Sprintf(":%d", as.GetInt("p"))
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "local/cheqbooq/server"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if s, err := server.New(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else if err := s.Routes(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
} else if err := s.Listen(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package account
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func Read(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "not impl", http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package account
|
||||||
|
|
||||||
|
type ReadRequest struct {
|
||||||
|
Accounts []string `json:"accounts"`
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package account
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type ReadResponse map[string]struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Meta json.RawMessage `json:"meta"`
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package account
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func Write(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "not impl", http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package account
|
||||||
|
|
||||||
|
import "local/cheqbooq/server/transaction"
|
||||||
|
|
||||||
|
type WriteRequest transaction.WriteRequest
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package account
|
||||||
|
|
||||||
|
import "local/cheqbooq/server/transaction"
|
||||||
|
|
||||||
|
type WriteResponse transaction.WriteResponse
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package balance
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func Read(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "not impl", http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package balance
|
||||||
|
|
||||||
|
type ReadRequest struct {
|
||||||
|
Accounts []string `json:"accounts"`
|
||||||
|
Start int64 `json:"start"`
|
||||||
|
Stop int64 `json:"stop"`
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
package balance
|
||||||
|
|
||||||
|
type ReadResponse map[string]map[int64]float32
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package balance
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
package balance
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"local/cheqbooq/config"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) Listen() error {
|
||||||
|
return http.ListenAndServe(config.Port, s)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"local/cheqbooq/server/account"
|
||||||
|
"local/cheqbooq/server/balance"
|
||||||
|
"local/cheqbooq/server/transaction"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) Routes() error {
|
||||||
|
routes := map[string]http.HandlerFunc{
|
||||||
|
"v1/balance": s.balance1,
|
||||||
|
"v1/transaction": s.transaction1,
|
||||||
|
"v1/account": s.account1,
|
||||||
|
}
|
||||||
|
for path, handler := range routes {
|
||||||
|
if err := s.Add(path, handler); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) balance1(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodPost:
|
||||||
|
balance.Read(w, r)
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) transaction1(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodPost:
|
||||||
|
transaction.Read(w, r)
|
||||||
|
case http.MethodPatch:
|
||||||
|
transaction.Write(w, r)
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) account1(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodPost:
|
||||||
|
account.Read(w, r)
|
||||||
|
case http.MethodPatch:
|
||||||
|
account.Write(w, r)
|
||||||
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import "local/router"
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
*router.Router
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() (*Server, error) {
|
||||||
|
return &Server{
|
||||||
|
Router: router.New(),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func Read(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "not impl", http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
import "local/cheqbooq/server/balance"
|
||||||
|
|
||||||
|
type ReadRequest balance.ReadRequest
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
type ReadResponse map[string]map[string]Transaction
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type Transaction struct {
|
||||||
|
Account string `json:"account"`
|
||||||
|
Amount float32 `json:"amount"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
Meta json.RawMessage `json:"meta"`
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func Write(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Error(w, "not impl", http.StatusNotImplemented)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
type WriteRequest map[string][]struct {
|
||||||
|
Op string `json:"op"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Value interface{} `json:"value"`
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package transaction
|
||||||
|
|
||||||
|
type WriteResponse map[string][]struct {
|
||||||
|
OK bool `json:"ok"`
|
||||||
|
Message string `json:"message,omitempty"`
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue