diff --git a/api.go b/api.go index 799c0ee..dbf0aaf 100644 --- a/api.go +++ b/api.go @@ -1,4 +1,4 @@ -package bond + package ss import ( ) diff --git a/btest.sh b/btest.sh new file mode 100755 index 0000000..f5e8192 --- /dev/null +++ b/btest.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# +go build -o ./exe/ ./cmd/test ./cmd/hook diff --git a/cmd/hook/main.go b/cmd/hook/main.go index 5d01d7b..21c3289 100644 --- a/cmd/hook/main.go +++ b/cmd/hook/main.go @@ -1,11 +1,11 @@ package main import ( - "vultras.su/core/bond" - //"vultras.su/core/bond/urlenc" - //"vultras.su/core/bond/methods" - "vultras.su/core/bond/statuses" - "vultras.su/core/bond/jsons" + "surdeus.su/core/ss" + //"surdeus.su/core/ss/urlenc" + //"surdeus.su/core/ss/methods" + "surdeus.su/core/ss/statuses" + "surdeus.su/core/ss/jsons" "fmt" //"io" //"net/url" @@ -40,12 +40,13 @@ type Account struct { SubDomain string `json:"subdomain"` } -var root = bond.Root(bond.Path(). -Def( +var root = ss.Root(ss.Path( + nil, +).Case( "hook", - /*bond.Method().Def( + /*ss.Method().Def( methods.Post,*/ - bond.Func(func(c *bond.Context){ + ss.Func(func(c *ss.Context){ reciever := WebhookRequest{} c.Scan(&reciever) if c.ScanErr() != nil { @@ -67,7 +68,7 @@ Def( } fmt.Printf("unescapeBody: %q\n", unesc) mp := map[string] any{} - err = bond.ParseStr(unesc, mp) + err = ss.ParseStr(unesc, mp) if err != nil { fmt.Printf("err:%s\n", err) return @@ -81,10 +82,10 @@ Def( c.SetStatus(statuses.OK) }), //), -).Def( +).Case( "auth", - bond.Func(func(c *bond.Context){ - }) + ss.Func(func(c *ss.Context){ + }), )) func main() { @@ -101,7 +102,7 @@ func main() { panic(err) }*/ //fmt.Printf("%#v\n", reciever) - srv := bond.Server{ + srv := ss.Server{ Addr: ":15080", Handler: root, } diff --git a/cmd/test/main.go b/cmd/test/main.go index 160205d..35c988b 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -1,114 +1,97 @@ package main import ( - "vultras.su/core/bond" - "vultras.su/core/bond/methods" - "vultras.su/core/bond/contents" - "vultras.su/core/bond/statuses" + "surdeus.su/core/ss" +) +import "surdeus.su/core/ss/methods" +import "surdeus.su/core/ss/contents" +import "surdeus.su/core/ss/statuses" + + +var testHandler = ss.Func(func(c *ss.Context){ + c.SetContentType(contents.Plain, contents.Utf8) + c.Printf( + "AbsPath: %q\n" + + "Prefix: %q\n" + + "Path: %q\n"+ + "Content-Type: %q\n", + c.AbsPath(), + c.PathPrefix(), + c.Path(), + c.ContentType(), + ) + c.Printf("Query:\n") + for k, vs := range c.Query() { + c.Printf("\t%q:\n", k) + for _, v := range vs { + c.Printf("\t\t%q\n", v) + } + } +}) + +var helloHandler = ss.Path( + // Default fallback handler. + testHandler, +).Case( + // Using the relative redirect to force us to the en. + "", ss.Redirect("en", statuses.Found), +).Case( + "en", ss.Func(func(c *ss.Context) { + c.Printf("Hello, World!") + }), +).Case( + "ru", ss.Func(func(c *ss.Context) { + c.Printf("Привет, Мир!") + }), ) type GetNotesOptions struct { Id int `json:"id"` - Name string `json:"name"` + Author string `json:"author"` + Title string `json:"title"` + Text string `json:"text"` } -var root = bond.Root(bond.Path(). -Case( - "", - bond.StaticFile("index.html"), +var apiHandler = ss.Path( + nil, ).Case( - "hello", - bond.Path().Case( - // Using the relative redirect to force us to the en. - "", bond.Redirect("en", statuses.Found), + "note", + ss.Method( + // The default handler. + nil, ).Case( - "en", bond.Func(func(c *bond.Context) { - c.Printf("Hello, World!") - }), - ).Case( - "ru", bond.Func(func(c *bond.Context) { - c.Printf("Привет, Мир!") - }), - ).Default(bond.Func(func(c *bond.Context){ - c.SetContentType(contents.Plain, contents.Utf8) - c.Printf( - "AbsPath: %q\n" + - "Prefix: %q\n" + - "Path: %q\n"+ - "Content-Type: %q\n", - c.AbsPath(), - c.PathPrefix(), - c.Path(), - c.ContentType(), - ) - c.Printf("Query:\n") - for k, vs := range c.Query() { - c.Printf("\t%q:\n", k) - for _, v := range vs { - c.Printf("\t\t%q\n", v) - } - } - })), -).Case( - "google", bond.Redirect("https://google.com", statuses.Found), -).Case( - "web", bond.StaticDir("./static"), -).Case( - "test", bond.Func(func(c *bond.Context) { - c.SetContentType(contents.Plain) - c.Printf( - "AbsPath: %q\n" + - "Prefix: %q\n" + - "Path: %q\n"+ - "Content-Type: %q\n", - c.AbsPath(), - c.PathPrefix(), - c.Path(), - c.ContentType(), - ) - c.Printf("Query:\n") - for k, vs := range c.Query() { - c.Printf("\t%q:\n", k) - for _, v := range vs { - c.Printf("\t\t%q\n", v) - } - } - }), -).Case( - "get-notes", - bond.Method().Case( methods.Get, - bond.Func(func(c *bond.Context) { + nil, + ).Case( + methods.Post, + ss.Func(func(c *ss.Context) { opts := GetNotesOptions{} c.Scan(&opts) c.Printf("%v", opts) }), ), -).Default( - bond.Func(func(c *bond.Context){ - c.SetContentType(contents.Plain) - c.Printf( - "AbsPath: %q\n" + - "Prefix: %q\n" + - "Path: %q\n"+ - "Content-Type: %q\n", - c.AbsPath(), - c.PathPrefix(), - c.Path(), - c.ContentType(), - ) - c.Printf("Query:\n") - for k, vs := range c.Query() { - c.Printf("\t%q:\n", k) - for _, v := range vs { - c.Printf("\t\t%q\n", v) - } - } - }), +) + +var root = ss.Root(ss.Path( + testHandler, +).Case( + // Static file serving example. + "", + ss.StaticFile("index.html"), +).Case( + "hello", + helloHandler, +).Case( + "google", ss.Redirect("https://google.com", statuses.Found), +).Case( + "web", ss.StaticDir("./static"), +).Case( + "api", + apiHandler, )) func main() { - srv := bond.Server{ + srv := ss.Server{ Addr: ":10800", Handler: root, } diff --git a/context.go b/context.go index 4902e50..377f2ec 100644 --- a/context.go +++ b/context.go @@ -1,4 +1,4 @@ -package bond + package ss import ( "io" @@ -7,8 +7,8 @@ import ( "net/http" "net/url" "fmt" - "vultras.su/core/bond/contents" - "vultras.su/core/bond/urlenc" + "surdeus.su/core/ss/contents" + "surdeus.su/core/ss/urlenc" ) type Context struct { diff --git a/decoder.go b/decoder.go index 2e9b108..80e7bf1 100644 --- a/decoder.go +++ b/decoder.go @@ -1,4 +1,4 @@ -package bond + package ss type Decoder interface { Decode(any) error diff --git a/errors.go b/errors.go index 867506d..52bb1aa 100644 --- a/errors.go +++ b/errors.go @@ -1,4 +1,4 @@ -package bond + package ss import ( "errors" diff --git a/go.mod b/go.mod index aa148a6..b7a08ea 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,3 @@ -module vultras.su/core/bond +module surdeus.su/core/ss go 1.21.3 - diff --git a/http.go b/http.go index edc955a..6b39639 100644 --- a/http.go +++ b/http.go @@ -1,9 +1,9 @@ -package bond + package ss import ( "net/http" - "vultras.su/core/bond/contents" - "vultras.su/core/bond/statuses" - "vultras.su/core/bond/methods" + "surdeus.su/core/ss/contents" + "surdeus.su/core/ss/statuses" + "surdeus.su/core/ss/methods" ) type Request = http.Request diff --git a/index.html b/index.html index 5c911a6..38a5c5e 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@
This is the index page!
- - - + + +