renaming.

This commit is contained in:
Andrey Parhomenko 2024-05-19 22:48:06 +05:00
parent 1e988c99af
commit ccca48d237
20 changed files with 176 additions and 146 deletions

2
api.go
View file

@ -1,4 +1,4 @@
package bond
package ss
import (
)

3
btest.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
#
go build -o ./exe/ ./cmd/test ./cmd/hook

View file

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

View file

@ -1,35 +1,14 @@
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"
type GetNotesOptions struct {
Id int `json:"id"`
Name string `json:"name"`
}
var root = bond.Root(bond.Path().
Case(
"",
bond.StaticFile("index.html"),
).Case(
"hello",
bond.Path().Case(
// Using the relative redirect to force us to the en.
"", bond.Redirect("en", statuses.Found),
).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){
var testHandler = ss.Func(func(c *ss.Context){
c.SetContentType(contents.Plain, contents.Utf8)
c.Printf(
"AbsPath: %q\n" +
@ -48,67 +27,71 @@ Case(
c.Printf("\t\t%q\n", v)
}
}
})),
})
var helloHandler = ss.Path(
// Default fallback handler.
testHandler,
).Case(
"google", bond.Redirect("https://google.com", statuses.Found),
// Using the relative redirect to force us to the en.
"", ss.Redirect("en", 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)
}
}
"en", ss.Func(func(c *ss.Context) {
c.Printf("Hello, World!")
}),
).Case(
"get-notes",
bond.Method().Case(
"ru", ss.Func(func(c *ss.Context) {
c.Printf("Привет, Мир!")
}),
)
type GetNotesOptions struct {
Id int `json:"id"`
Author string `json:"author"`
Title string `json:"title"`
Text string `json:"text"`
}
var apiHandler = ss.Path(
nil,
).Case(
"note",
ss.Method(
// The default handler.
nil,
).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,
}

View file

@ -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 {

View file

@ -1,4 +1,4 @@
package bond
package ss
type Decoder interface {
Decode(any) error

View file

@ -1,4 +1,4 @@
package bond
package ss
import (
"errors"

3
go.mod
View file

@ -1,4 +1,3 @@
module vultras.su/core/bond
module surdeus.su/core/ss
go 1.21.3

View file

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

View file

@ -4,7 +4,7 @@
<p>
This is the index page!
</p>
<div><a href="hello/en">English Hello</a></div>
<div><a href="hello/ru">Русский Привет</a></div>
<div><a href="web/">Static files directory</a></div>
<div><a href="./hello/en">English Hello</a></div>
<div><a href="./hello/ru">Русский Привет</a></div>
<div><a href="./web/">Static files directory</a></div>
</body></html>

56
jsons/time.go Normal file
View file

@ -0,0 +1,56 @@
package jsons
import (
//"time"
)
// Implementing the interrface provides
// way to easily decode time and type safely
// specify how to decode field.
/*type TimeDecoder interface {
DecodeTime([]byte) (time.Time, error)
}
// Implementing the interface provides type safe
// way to specify how to encode and decode time.
type TimeEncoder interface {
EncodeTime(time.Time) ([]byte, error)
}
// The type provides fast way to define
// parsable time variations.
// Like `t jsons.Time[jsons.]`
type Time[D TimeDecoder, E TimeEncoder] struct {
time.Time
}
func (t *Time[D, E]) UnmarshalJSON(bts []byte) error {
var adec [1]D
dec := adec[0]
err, ret := dec.DecodeTime(bts)
if err != nil {
return err
}
t.Time = ret
return nil
}
func (t *Time[D, E]) MarshalJSON() ([]byte, error) {
var aenc [1]E
enc := enc[0]
bts, err := enc.EncodeTime(t.Time)
if err != nil {
return nil, err
}
return bts, err
}
type DatetimeLocal struct{}
func (dt DatetimeLocal) DecodeTime(bts []byte) (time.Time, error) {
return dt.Format("1986-01-28T11:38:00.010"), nil
}*/

View file

@ -1,4 +1,4 @@
package bond
package ss
// The type implements method routing.
type MethodRouter struct {
@ -7,9 +7,10 @@ type MethodRouter struct {
}
// Returns new empty MethodRouter.
func Method() *MethodRouter {
func Method(def Handler) *MethodRouter {
ret := &MethodRouter{}
ret.methodMap = make(map[ReqMethod]Handler)
ret.def = def
return ret
}

View file

@ -1,2 +1,2 @@
package bond
package ss

13
path.go
View file

@ -1,4 +1,4 @@
package bond
package ss
import (
"strings"
@ -12,10 +12,12 @@ type PathRouter struct {
def Handler
}
// Returns new empty PathRouter.
func Path() *PathRouter {
// Returns new empty PathRouter with the def
// specified as the default fallback.
func Path(def Handler) *PathRouter {
ret := &PathRouter{}
ret.pathMap = map[string] Handler{}
ret.def = def
return ret
}
@ -68,9 +70,4 @@ func (router *PathRouter) Handle(c *Context) {
handler.Handle(c)
}
// The handler to fall to if no match for paths in the router.
func (router *PathRouter) Default(h Handler) *PathRouter {
router.def = h
return router
}

2
re.go
View file

@ -1,4 +1,4 @@
package bond
package ss
import (
//"regexp"

View file

@ -1,4 +1,4 @@
package bond
package ss
// The type implements the entry point
// for all the request for the server.

View file

@ -1,3 +1,3 @@
package bond
package ss

View file

@ -1,4 +1,4 @@
package bond
package ss
// Returns the handler that redirects to the specified URL (u)
func Redirect(u string, status Status) Handler {

View file

@ -1,4 +1,4 @@
package bond
package ss
import (
"net/http"

View file

@ -1,10 +0,0 @@
version: 3
tasks:
btest:
cmds:
- go build ./cmd/test/
bhook:
cmds:
- go build ./cmd/hook/