Not impl endpoints

master
bel 2020-04-12 16:56:14 +00:00
parent 79600941be
commit 0b4ecd1916
23 changed files with 213 additions and 0 deletions

23
config/config.go Normal file
View File

@ -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"))
}

13
main.go Normal file
View File

@ -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)
}
}

7
server/account/read.go Normal file
View File

@ -0,0 +1,7 @@
package account
import "net/http"
func Read(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not impl", http.StatusNotImplemented)
}

View File

@ -0,0 +1,5 @@
package account
type ReadRequest struct {
Accounts []string `json:"accounts"`
}

View File

@ -0,0 +1,8 @@
package account
import "encoding/json"
type ReadResponse map[string]struct {
Name string `json:"name"`
Meta json.RawMessage `json:"meta"`
}

7
server/account/write.go Normal file
View File

@ -0,0 +1,7 @@
package account
import "net/http"
func Write(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not impl", http.StatusNotImplemented)
}

View File

@ -0,0 +1,5 @@
package account
import "local/cheqbooq/server/transaction"
type WriteRequest transaction.WriteRequest

View File

@ -0,0 +1,5 @@
package account
import "local/cheqbooq/server/transaction"
type WriteResponse transaction.WriteResponse

7
server/balance/read.go Normal file
View File

@ -0,0 +1,7 @@
package balance
import "net/http"
func Read(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not impl", http.StatusNotImplemented)
}

View File

@ -0,0 +1,7 @@
package balance
type ReadRequest struct {
Accounts []string `json:"accounts"`
Start int64 `json:"start"`
Stop int64 `json:"stop"`
}

View File

@ -0,0 +1,3 @@
package balance
type ReadResponse map[string]map[int64]float32

View File

@ -0,0 +1 @@
package balance

View File

@ -0,0 +1 @@
package balance

10
server/listen.go Normal file
View File

@ -0,0 +1,10 @@
package server
import (
"local/cheqbooq/config"
"net/http"
)
func (s *Server) Listen() error {
return http.ListenAndServe(config.Port, s)
}

53
server/routes.go Normal file
View File

@ -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)
}
}

13
server/server.go Normal file
View File

@ -0,0 +1,13 @@
package server
import "local/router"
type Server struct {
*router.Router
}
func New() (*Server, error) {
return &Server{
Router: router.New(),
}, nil
}

View File

@ -0,0 +1,7 @@
package transaction
import "net/http"
func Read(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not impl", http.StatusNotImplemented)
}

View File

@ -0,0 +1,5 @@
package transaction
import "local/cheqbooq/server/balance"
type ReadRequest balance.ReadRequest

View File

@ -0,0 +1,3 @@
package transaction
type ReadResponse map[string]map[string]Transaction

View File

@ -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"`
}

View File

@ -0,0 +1,7 @@
package transaction
import "net/http"
func Write(w http.ResponseWriter, r *http.Request) {
http.Error(w, "not impl", http.StatusNotImplemented)
}

View File

@ -0,0 +1,7 @@
package transaction
type WriteRequest map[string][]struct {
Op string `json:"op"`
Path string `json:"path"`
Value interface{} `json:"value"`
}

View File

@ -0,0 +1,6 @@
package transaction
type WriteResponse map[string][]struct {
OK bool `json:"ok"`
Message string `json:"message,omitempty"`
}