feat: moving to the VULTRAS.

This commit is contained in:
Andrey Parhomenko 2024-01-09 07:40:32 +03:00
parent b4183239f7
commit 89be9a69be
5 changed files with 14 additions and 13 deletions

5
api.go
View file

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"fmt" "fmt"
"github.com/di4f/bond/contents" "vultras.su/core/bond/contents"
) )
type Decoder interface { type Decoder interface {
@ -14,6 +14,7 @@ type Decoder interface {
} }
type Func func(*Context) type Func func(*Context)
func (fn Func) ServeHTTP(w ResponseWriter, r *Request) { func (fn Func) ServeHTTP(w ResponseWriter, r *Request) {
fn(&Context{ fn(&Context{
R: r, R: r,
@ -66,7 +67,7 @@ func (c *Context) Scan(v any) bool {
if c.dec == nil { if c.dec == nil {
typ := c.ContentType() typ := c.ContentType()
switch typ { switch typ {
case contents.Json : case contents.Json:
c.dec = json.NewDecoder(c.R.Body) c.dec = json.NewDecoder(c.R.Body)
default: default:
c.scanErr = UnknownContentTypeErr c.scanErr = UnknownContentTypeErr

View file

@ -1,9 +1,9 @@
package main package main
import ( import (
"github.com/di4f/bond" "vultras.su/core/bond"
"github.com/di4f/bond/methods" "vultras.su/core/bond/methods"
"github.com/di4f/bond/contents" "vultras.su/core/bond/contents"
) )
type GetNotesOptions struct { type GetNotesOptions struct {
@ -54,7 +54,7 @@ var root = bond.Mux().
"get-notes", "get-notes",
bond.Method().Def( bond.Method().Def(
methods.Get, methods.Get,
bond.Func(func(c *bond.Context){ bond.Func(func(c *bond.Context) {
opts := GetNotesOptions{} opts := GetNotesOptions{}
c.Scan(&opts) c.Scan(&opts)
c.Printf("%v", opts) c.Printf("%v", opts)

2
go.mod
View file

@ -1,3 +1,3 @@
module github.com/di4f/bond module vultras.su/core/bond
go 1.21.3 go 1.21.3

View file

@ -2,18 +2,18 @@ package bond
import ( import (
"net/http" "net/http"
"github.com/di4f/bond/methods" "vultras.su/core/bond/methods"
) )
// The type implements functionality for multiplexing // The type implements functionality for multiplexing
// the methods. // the methods.
type MethodRouter struct { type MethodRouter struct {
methodMap map[methods.Method] Handler methodMap map[methods.Method]Handler
} }
func Method() *MethodRouter { func Method() *MethodRouter {
ret := &MethodRouter{} ret := &MethodRouter{}
ret.methodMap = make(map[methods.Method] Handler) ret.methodMap = make(map[methods.Method]Handler)
return ret return ret
} }

View file

@ -3,5 +3,5 @@ version: 3
tasks: tasks:
btest: btest:
cmds: cmds:
- go build -o ./test ./cmd/test/ - go build ./cmd/test/