From 89a2d152accf0ba971bbeecae0f86e769178e464 Mon Sep 17 00:00:00 2001 From: Kanan Rahimov Date: Mon, 7 Feb 2022 22:37:15 +0100 Subject: [PATCH 1/6] echo static assets --- echo/assets/js/index.js | 1 + echo/assets/pages/index.html | 6 ++++++ echo/server.go | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 echo/assets/js/index.js create mode 100644 echo/assets/pages/index.html diff --git a/echo/assets/js/index.js b/echo/assets/js/index.js new file mode 100644 index 0000000..8df6f4a --- /dev/null +++ b/echo/assets/js/index.js @@ -0,0 +1 @@ +console.log("demo") \ No newline at end of file diff --git a/echo/assets/pages/index.html b/echo/assets/pages/index.html new file mode 100644 index 0000000..9575e74 --- /dev/null +++ b/echo/assets/pages/index.html @@ -0,0 +1,6 @@ + + +

Echo

+ + + diff --git a/echo/server.go b/echo/server.go index ea2f981..de6c8b1 100644 --- a/echo/server.go +++ b/echo/server.go @@ -22,6 +22,9 @@ func main() { return c.String(http.StatusOK, "Hello, Echo!") }) + app.Static("/static", "assets") + app.File("/website", "assets/pages/index.html") + app.POST("/entities", addEntity) app.PUT("/entities", updateEntity) app.GET("/entities", listEntities) From fdc0172883d5d71152d86105af64d26af181fe52 Mon Sep 17 00:00:00 2001 From: Kanan Rahimov Date: Tue, 8 Feb 2022 23:03:00 +0100 Subject: [PATCH 2/6] echo submit form --- echo/Notes.md | 5 +++++ echo/assets/pages/index.html | 17 +++++++++++++++++ echo/go.mod | 6 +++--- echo/go.sum | 8 ++++---- echo/server.go | 17 +++++++++++++++++ .../CoderVlogger/go-web-frameworks/pkg/model.go | 6 +++--- .../golang.org/x/sys/unix/syscall_linux.go | 1 - .../x/sys/unix/syscall_linux_alarm.go | 14 ++++++++++++++ .../golang.org/x/sys/unix/zerrors_linux.go | 3 ++- .../golang.org/x/sys/unix/zsyscall_linux_386.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_amd64.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_mips.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_mips64.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_mipsle.go | 13 ++++++++++++- .../golang.org/x/sys/unix/zsyscall_linux_ppc.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_ppc64.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_ppc64le.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_s390x.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_sparc64.go | 13 ++++++++++++- echo/vendor/modules.txt | 6 +++--- iris/go.mod | 8 ++++---- iris/go.sum | 12 ++++++------ .../microcosm-cc/bluemonday/policy.go | 2 +- .../golang.org/x/sys/unix/syscall_linux.go | 1 - .../x/sys/unix/syscall_linux_alarm.go | 14 ++++++++++++++ .../golang.org/x/sys/unix/zerrors_linux.go | 3 ++- .../golang.org/x/sys/unix/zsyscall_linux_386.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_amd64.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_mips.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_mips64.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_mipsle.go | 13 ++++++++++++- .../golang.org/x/sys/unix/zsyscall_linux_ppc.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_ppc64.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_ppc64le.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_s390x.go | 13 ++++++++++++- .../x/sys/unix/zsyscall_linux_sparc64.go | 13 ++++++++++++- iris/vendor/modules.txt | 8 ++++---- pkg/model.go | 6 +++--- 38 files changed, 342 insertions(+), 55 deletions(-) create mode 100644 echo/Notes.md create mode 100644 echo/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go create mode 100644 iris/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go diff --git a/echo/Notes.md b/echo/Notes.md new file mode 100644 index 0000000..3de1b6b --- /dev/null +++ b/echo/Notes.md @@ -0,0 +1,5 @@ +Open topics: + +- How to use model without adding tags? +- How to redirect with custom HTTP Method (defaults to "POST")? +- Org url structure when BE API and FE served from the same app diff --git a/echo/assets/pages/index.html b/echo/assets/pages/index.html index 9575e74..c27cc92 100644 --- a/echo/assets/pages/index.html +++ b/echo/assets/pages/index.html @@ -2,5 +2,22 @@

Echo

+

Submit a new entity:

+
+ + +

+ + + +

+ + + +

+ + +
+ diff --git a/echo/go.mod b/echo/go.mod index 926d692..16f9a21 100644 --- a/echo/go.mod +++ b/echo/go.mod @@ -5,7 +5,7 @@ go 1.17 replace github.com/CoderVlogger/go-web-frameworks/pkg => ../pkg require ( - github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-00010101000000-000000000000 + github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220207162710-24ad69459d6b github.com/labstack/echo/v4 v4.6.3 ) @@ -15,8 +15,8 @@ require ( github.com/mattn/go-isatty v0.0.14 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.1 // indirect - golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect + golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect - golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect + golang.org/x/sys v0.0.0-20220207234003-57398862261d // indirect golang.org/x/text v0.3.7 // indirect ) diff --git a/echo/go.sum b/echo/go.sum index c395089..23807e7 100644 --- a/echo/go.sum +++ b/echo/go.sum @@ -21,8 +21,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE= -golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab h1:lnZ4LoV0UMdibeCUfIB2a4uFwRu491WX/VB2reB8xNc= +golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -35,8 +35,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= -golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBanX+88Z/OtdvsrEv1Djc= +golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/echo/server.go b/echo/server.go index de6c8b1..1f38432 100644 --- a/echo/server.go +++ b/echo/server.go @@ -24,6 +24,7 @@ func main() { app.Static("/static", "assets") app.File("/website", "assets/pages/index.html") + app.POST("/website", formSubmitEntity) app.POST("/entities", addEntity) app.PUT("/entities", updateEntity) @@ -34,6 +35,22 @@ func main() { app.Logger.Fatal(app.Start(":8080")) } +func formSubmitEntity(ctx echo.Context) error { + entity := pkg.Entity{} + + if err := ctx.Bind(&entity); err != nil { + return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) + } + + if err := entityStorage.Add(&entity); err != nil { + return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) + } + + // TODO: What's the convention when we do form submit. + // return ctx.Redirect(http.StatusTemporaryRedirect, "/website") + return ctx.File("assets/pages/index.html") +} + func addEntity(ctx echo.Context) error { entity := pkg.Entity{} diff --git a/echo/vendor/github.com/CoderVlogger/go-web-frameworks/pkg/model.go b/echo/vendor/github.com/CoderVlogger/go-web-frameworks/pkg/model.go index 7daf8d0..b3eaf4e 100644 --- a/echo/vendor/github.com/CoderVlogger/go-web-frameworks/pkg/model.go +++ b/echo/vendor/github.com/CoderVlogger/go-web-frameworks/pkg/model.go @@ -7,9 +7,9 @@ type ( Entity struct { ID string `json:"id"` - Type EntityType `json:"type"` - Name string `json:"name"` - Description string `json:"description"` + Type EntityType `json:"type" form:"type"` + Name string `json:"name" form:"name"` + Description string `json:"description" form:"description"` } EntityType string diff --git a/echo/vendor/golang.org/x/sys/unix/syscall_linux.go b/echo/vendor/golang.org/x/sys/unix/syscall_linux.go index f432b06..e52e8b9 100644 --- a/echo/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/echo/vendor/golang.org/x/sys/unix/syscall_linux.go @@ -2318,7 +2318,6 @@ type RemoteIovec struct { * Unimplemented */ // AfsSyscall -// Alarm // ArchPrctl // Brk // ClockNanosleep diff --git a/echo/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go b/echo/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go new file mode 100644 index 0000000..08086ac --- /dev/null +++ b/echo/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go @@ -0,0 +1,14 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build linux && (386 || amd64 || mips || mipsle || mips64 || mipsle || ppc64 || ppc64le || ppc || s390x || sparc64) +// +build linux +// +build 386 amd64 mips mipsle mips64 mipsle ppc64 ppc64le ppc s390x sparc64 + +package unix + +// SYS_ALARM is not defined on arm or riscv, but is available for other GOARCH +// values. + +//sys Alarm(seconds uint) (remaining uint, err error) diff --git a/echo/vendor/golang.org/x/sys/unix/zerrors_linux.go b/echo/vendor/golang.org/x/sys/unix/zerrors_linux.go index 4e54205..6bce658 100644 --- a/echo/vendor/golang.org/x/sys/unix/zerrors_linux.go +++ b/echo/vendor/golang.org/x/sys/unix/zerrors_linux.go @@ -38,7 +38,8 @@ const ( AF_KEY = 0xf AF_LLC = 0x1a AF_LOCAL = 0x1 - AF_MAX = 0x2d + AF_MAX = 0x2e + AF_MCTP = 0x2d AF_MPLS = 0x1c AF_NETBEUI = 0xd AF_NETLINK = 0x10 diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go index ff90c81..2fc6271 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go +// go run mksyscall.go -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && 386 @@ -524,3 +524,14 @@ func utimes(path string, times *[2]Timeval) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go index fa7d3db..21fb850 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go +// go run mksyscall.go -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && amd64 @@ -691,3 +691,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go index 6d15528..eab7ab9 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go +// go run mksyscall.go -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mips @@ -702,3 +702,14 @@ func setrlimit(resource int, rlim *rlimit32) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go index 1e20d72..dc3f47f 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go +// go run mksyscall.go -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mips64 @@ -696,3 +696,14 @@ func stat(path string, st *stat_t) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go index a0440c1..691f3de 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go +// go run mksyscall.go -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mipsle @@ -702,3 +702,14 @@ func setrlimit(resource int, rlim *rlimit32) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go index 5864b9c..5ce957c 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -b32 -tags linux,ppc syscall_linux.go syscall_linux_ppc.go +// go run mksyscall.go -b32 -tags linux,ppc syscall_linux.go syscall_linux_ppc.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc @@ -707,3 +707,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go index beeb49e..82c5b63 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go +// go run mksyscall.go -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc64 @@ -753,3 +753,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go index 53139b8..178847e 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go +// go run mksyscall.go -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc64le @@ -753,3 +753,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go index 202add3..9e462a9 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,s390x syscall_linux.go syscall_linux_s390x.go +// go run mksyscall.go -tags linux,s390x syscall_linux.go syscall_linux_s390x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && s390x @@ -533,3 +533,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go index 2ab268c..ea7d7c2 100644 --- a/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +++ b/echo/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go +// go run mksyscall.go -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && sparc64 @@ -697,3 +697,14 @@ func utimes(path string, times *[2]Timeval) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/echo/vendor/modules.txt b/echo/vendor/modules.txt index 9cbfe32..8b06787 100644 --- a/echo/vendor/modules.txt +++ b/echo/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-00010101000000-000000000000 => ../pkg +# github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220207162710-24ad69459d6b => ../pkg ## explicit; go 1.16 github.com/CoderVlogger/go-web-frameworks/pkg # github.com/labstack/echo/v4 v4.6.3 @@ -20,7 +20,7 @@ github.com/valyala/bytebufferpool # github.com/valyala/fasttemplate v1.2.1 ## explicit; go 1.12 github.com/valyala/fasttemplate -# golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 +# golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab ## explicit; go 1.17 golang.org/x/crypto/acme golang.org/x/crypto/acme/autocert @@ -31,7 +31,7 @@ golang.org/x/net/http2 golang.org/x/net/http2/h2c golang.org/x/net/http2/hpack golang.org/x/net/idna -# golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 +# golang.org/x/sys v0.0.0-20220207234003-57398862261d ## explicit; go 1.17 golang.org/x/sys/internal/unsafeheader golang.org/x/sys/unix diff --git a/iris/go.mod b/iris/go.mod index ce52c71..a5dca05 100644 --- a/iris/go.mod +++ b/iris/go.mod @@ -5,7 +5,7 @@ go 1.17 replace github.com/CoderVlogger/go-web-frameworks/pkg => ../pkg require ( - github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220203181310-76ddbdf1f6dd + github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220207162710-24ad69459d6b github.com/kataras/iris/v12 v12.2.0-alpha5.0.20220108175433-f633ab4b99fd ) @@ -35,7 +35,7 @@ require ( github.com/kataras/tunnel v0.0.3 // indirect github.com/klauspost/compress v1.14.2 // indirect github.com/mailru/easyjson v0.7.7 // indirect - github.com/microcosm-cc/bluemonday v1.0.17 // indirect + github.com/microcosm-cc/bluemonday v1.0.18 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect @@ -46,9 +46,9 @@ require ( github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/yosssi/ace v0.0.5 // indirect - golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect + golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab // indirect golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect - golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 // indirect + golang.org/x/sys v0.0.0-20220207234003-57398862261d // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect google.golang.org/protobuf v1.27.1 // indirect diff --git a/iris/go.sum b/iris/go.sum index 6513f76..c5b3530 100644 --- a/iris/go.sum +++ b/iris/go.sum @@ -137,8 +137,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mediocregopher/radix/v3 v3.6.0/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= github.com/mediocregopher/radix/v3 v3.8.0/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8= github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM= -github.com/microcosm-cc/bluemonday v1.0.17 h1:Z1a//hgsQ4yjC+8zEkV8IWySkXnsxmdSY642CTFQb5Y= -github.com/microcosm-cc/bluemonday v1.0.17/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM= +github.com/microcosm-cc/bluemonday v1.0.18 h1:6HcxvXDAi3ARt3slx6nTesbvorIc3QeTzBNRvWktHBo= +github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM= github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -246,8 +246,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 h1:71vQrMauZZhcTVK6KdYM+rklehEEwb3E+ZhaE5jrPrE= -golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab h1:lnZ4LoV0UMdibeCUfIB2a4uFwRu491WX/VB2reB8xNc= +golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -288,8 +288,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 h1:XDXtA5hveEEV8JB2l7nhMTp3t3cHp9ZpwcdjqyEWLlo= -golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBanX+88Z/OtdvsrEv1Djc= +golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/iris/vendor/github.com/microcosm-cc/bluemonday/policy.go b/iris/vendor/github.com/microcosm-cc/bluemonday/policy.go index 8a08163..1a5e00c 100644 --- a/iris/vendor/github.com/microcosm-cc/bluemonday/policy.go +++ b/iris/vendor/github.com/microcosm-cc/bluemonday/policy.go @@ -707,7 +707,7 @@ func (p *Policy) AllowURLSchemeWithCustomPolicy( func (p *Policy) RequireSandboxOnIFrame(vals ...SandboxValue) { p.requireSandboxOnIFrame = make(map[string]bool) - for val := range vals { + for _, val := range vals { switch SandboxValue(val) { case SandboxAllowDownloads: p.requireSandboxOnIFrame["allow-downloads"] = true diff --git a/iris/vendor/golang.org/x/sys/unix/syscall_linux.go b/iris/vendor/golang.org/x/sys/unix/syscall_linux.go index f432b06..e52e8b9 100644 --- a/iris/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/iris/vendor/golang.org/x/sys/unix/syscall_linux.go @@ -2318,7 +2318,6 @@ type RemoteIovec struct { * Unimplemented */ // AfsSyscall -// Alarm // ArchPrctl // Brk // ClockNanosleep diff --git a/iris/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go b/iris/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go new file mode 100644 index 0000000..08086ac --- /dev/null +++ b/iris/vendor/golang.org/x/sys/unix/syscall_linux_alarm.go @@ -0,0 +1,14 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build linux && (386 || amd64 || mips || mipsle || mips64 || mipsle || ppc64 || ppc64le || ppc || s390x || sparc64) +// +build linux +// +build 386 amd64 mips mipsle mips64 mipsle ppc64 ppc64le ppc s390x sparc64 + +package unix + +// SYS_ALARM is not defined on arm or riscv, but is available for other GOARCH +// values. + +//sys Alarm(seconds uint) (remaining uint, err error) diff --git a/iris/vendor/golang.org/x/sys/unix/zerrors_linux.go b/iris/vendor/golang.org/x/sys/unix/zerrors_linux.go index 4e54205..6bce658 100644 --- a/iris/vendor/golang.org/x/sys/unix/zerrors_linux.go +++ b/iris/vendor/golang.org/x/sys/unix/zerrors_linux.go @@ -38,7 +38,8 @@ const ( AF_KEY = 0xf AF_LLC = 0x1a AF_LOCAL = 0x1 - AF_MAX = 0x2d + AF_MAX = 0x2e + AF_MCTP = 0x2d AF_MPLS = 0x1c AF_NETBEUI = 0xd AF_NETLINK = 0x10 diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go index ff90c81..2fc6271 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_386.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go +// go run mksyscall.go -l32 -tags linux,386 syscall_linux.go syscall_linux_386.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && 386 @@ -524,3 +524,14 @@ func utimes(path string, times *[2]Timeval) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go index fa7d3db..21fb850 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go +// go run mksyscall.go -tags linux,amd64 syscall_linux.go syscall_linux_amd64.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && amd64 @@ -691,3 +691,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go index 6d15528..eab7ab9 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go +// go run mksyscall.go -b32 -arm -tags linux,mips syscall_linux.go syscall_linux_mipsx.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mips @@ -702,3 +702,14 @@ func setrlimit(resource int, rlim *rlimit32) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go index 1e20d72..dc3f47f 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go +// go run mksyscall.go -tags linux,mips64 syscall_linux.go syscall_linux_mips64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mips64 @@ -696,3 +696,14 @@ func stat(path string, st *stat_t) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go index a0440c1..691f3de 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go +// go run mksyscall.go -l32 -arm -tags linux,mipsle syscall_linux.go syscall_linux_mipsx.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && mipsle @@ -702,3 +702,14 @@ func setrlimit(resource int, rlim *rlimit32) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go index 5864b9c..5ce957c 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -b32 -tags linux,ppc syscall_linux.go syscall_linux_ppc.go +// go run mksyscall.go -b32 -tags linux,ppc syscall_linux.go syscall_linux_ppc.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc @@ -707,3 +707,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go index beeb49e..82c5b63 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go +// go run mksyscall.go -tags linux,ppc64 syscall_linux.go syscall_linux_ppc64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc64 @@ -753,3 +753,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go index 53139b8..178847e 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go +// go run mksyscall.go -tags linux,ppc64le syscall_linux.go syscall_linux_ppc64x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && ppc64le @@ -753,3 +753,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go index 202add3..9e462a9 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,s390x syscall_linux.go syscall_linux_s390x.go +// go run mksyscall.go -tags linux,s390x syscall_linux.go syscall_linux_s390x.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && s390x @@ -533,3 +533,14 @@ func kexecFileLoad(kernelFd int, initrdFd int, cmdlineLen int, cmdline string, f } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go index 2ab268c..ea7d7c2 100644 --- a/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +++ b/iris/vendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go @@ -1,4 +1,4 @@ -// go run mksyscall.go -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go +// go run mksyscall.go -tags linux,sparc64 syscall_linux.go syscall_linux_sparc64.go syscall_linux_alarm.go // Code generated by the command above; see README.md. DO NOT EDIT. //go:build linux && sparc64 @@ -697,3 +697,14 @@ func utimes(path string, times *[2]Timeval) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func Alarm(seconds uint) (remaining uint, err error) { + r0, _, e1 := Syscall(SYS_ALARM, uintptr(seconds), 0, 0) + remaining = uint(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/iris/vendor/modules.txt b/iris/vendor/modules.txt index 3c8d335..6482414 100644 --- a/iris/vendor/modules.txt +++ b/iris/vendor/modules.txt @@ -8,7 +8,7 @@ github.com/CloudyKit/fastprinter # github.com/CloudyKit/jet/v6 v6.1.0 ## explicit; go 1.12 github.com/CloudyKit/jet/v6 -# github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220203181310-76ddbdf1f6dd => ../pkg +# github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220207162710-24ad69459d6b => ../pkg ## explicit; go 1.16 github.com/CoderVlogger/go-web-frameworks/pkg # github.com/Shopify/goreferrer v0.0.0-20210630161223-536fa16abd6f @@ -118,7 +118,7 @@ github.com/mailru/easyjson github.com/mailru/easyjson/buffer github.com/mailru/easyjson/jlexer github.com/mailru/easyjson/jwriter -# github.com/microcosm-cc/bluemonday v1.0.17 +# github.com/microcosm-cc/bluemonday v1.0.18 ## explicit; go 1.16 github.com/microcosm-cc/bluemonday github.com/microcosm-cc/bluemonday/css @@ -168,7 +168,7 @@ github.com/vmihailenco/tagparser/v2/internal/parser # github.com/yosssi/ace v0.0.5 ## explicit github.com/yosssi/ace -# golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 +# golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab ## explicit; go 1.17 golang.org/x/crypto/acme golang.org/x/crypto/acme/autocert @@ -178,7 +178,7 @@ golang.org/x/net/html golang.org/x/net/html/atom golang.org/x/net/idna golang.org/x/net/publicsuffix -# golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27 +# golang.org/x/sys v0.0.0-20220207234003-57398862261d ## explicit; go 1.17 golang.org/x/sys/internal/unsafeheader golang.org/x/sys/unix diff --git a/pkg/model.go b/pkg/model.go index 7daf8d0..b3eaf4e 100644 --- a/pkg/model.go +++ b/pkg/model.go @@ -7,9 +7,9 @@ type ( Entity struct { ID string `json:"id"` - Type EntityType `json:"type"` - Name string `json:"name"` - Description string `json:"description"` + Type EntityType `json:"type" form:"type"` + Name string `json:"name" form:"name"` + Description string `json:"description" form:"description"` } EntityType string From 4d94f16342a02e20a13f920e128484a79012e780 Mon Sep 17 00:00:00 2001 From: Kanan Rahimov Date: Wed, 9 Feb 2022 22:31:31 +0100 Subject: [PATCH 3/6] refactor routers --- echo/Notes.md | 16 +++++ echo/api.go | 91 ++++++++++++++++++++++++++ echo/assets/pages/index.html | 2 + echo/server.go | 123 ++++++----------------------------- echo/website.go | 30 +++++++++ 5 files changed, 159 insertions(+), 103 deletions(-) create mode 100644 echo/api.go create mode 100644 echo/website.go diff --git a/echo/Notes.md b/echo/Notes.md index 3de1b6b..b0b431a 100644 --- a/echo/Notes.md +++ b/echo/Notes.md @@ -3,3 +3,19 @@ Open topics: - How to use model without adding tags? - How to redirect with custom HTTP Method (defaults to "POST")? - Org url structure when BE API and FE served from the same app +- Refactor API urls (maybe group them) + + +API: + + /api + +Static / Assets: + + /static + +Front-end / Website: + + / + + diff --git a/echo/api.go b/echo/api.go new file mode 100644 index 0000000..55b9bf0 --- /dev/null +++ b/echo/api.go @@ -0,0 +1,91 @@ +package main + +import ( + "net/http" + "strconv" + + "github.com/CoderVlogger/go-web-frameworks/pkg" + "github.com/labstack/echo/v4" +) + +func (wa *WebApplication) initAPIRoutes() { + wa.echoApp.POST(apiPrefix+"entities", wa.addEntity) + wa.echoApp.PUT(apiPrefix+"entities", wa.updateEntity) + wa.echoApp.GET(apiPrefix+"entities", wa.listEntities) + wa.echoApp.GET(apiPrefix+"entities/:id", wa.getEntity) + wa.echoApp.DELETE(apiPrefix+"entities/:id", wa.deleteEntity) +} + +func (wa *WebApplication) addEntity(ctx echo.Context) error { + entity := pkg.Entity{} + + if err := ctx.Bind(&entity); err != nil { + return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) + } + + if err := wa.entityRepository.Add(&entity); err != nil { + return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) + } + + return ctx.JSON(http.StatusCreated, entity) +} + +func (wa *WebApplication) updateEntity(ctx echo.Context) error { + entity := pkg.Entity{} + + if err := ctx.Bind(&entity); err != nil { + return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) + } + + if err := wa.entityRepository.Update(&entity); err != nil { + return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) + } + + return ctx.JSON(http.StatusOK, entity) +} + +func (wa *WebApplication) getEntity(ctx echo.Context) error { + entityID := ctx.Param("id") + + entity, err := wa.entityRepository.Get(entityID) + if err != nil { + return ctx.JSON(http.StatusNotFound, pkg.TextResponse{Message: err.Error()}) + } + + if entity == nil { + return ctx.JSON(http.StatusNotFound, pkg.TextResponse{Message: "entity not found"}) + } + + return ctx.JSON(http.StatusOK, entity) +} + +func (wa *WebApplication) listEntities(ctx echo.Context) error { + var err error + + page := 1 + + pageStr := ctx.QueryParam("page") + if pageStr != "" { + page, err = strconv.Atoi(pageStr) + if err != nil { + return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) + } + } + + entities, err := wa.entityRepository.List(page, pageSize) + if err != nil { + return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) + } + + return ctx.JSON(http.StatusOK, entities) +} + +func (wa *WebApplication) deleteEntity(ctx echo.Context) error { + entityID := ctx.Param("id") + + if err := wa.entityRepository.Delete(entityID); err != nil { + return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) + } + + return ctx.JSON(http.StatusOK, pkg.TextResponse{Message: "entity deleted"}) +} diff --git a/echo/assets/pages/index.html b/echo/assets/pages/index.html index c27cc92..211fb61 100644 --- a/echo/assets/pages/index.html +++ b/echo/assets/pages/index.html @@ -3,6 +3,8 @@

Echo

Submit a new entity:

+ +
diff --git a/echo/server.go b/echo/server.go index 1f38432..58600ce 100644 --- a/echo/server.go +++ b/echo/server.go @@ -1,126 +1,43 @@ package main import ( - "net/http" - "strconv" - "github.com/CoderVlogger/go-web-frameworks/pkg" "github.com/labstack/echo/v4" ) var ( - pageSize = 4 - entityStorage pkg.EntityRepository = pkg.NewEntityMemoryRepository() + pageSize = 4 + apiPrefix = "/api/" ) -func main() { - app := echo.New() - entityStorage.Init() - - app.GET("/", func(c echo.Context) error { - return c.String(http.StatusOK, "Hello, Echo!") - }) - - app.Static("/static", "assets") - app.File("/website", "assets/pages/index.html") - app.POST("/website", formSubmitEntity) - - app.POST("/entities", addEntity) - app.PUT("/entities", updateEntity) - app.GET("/entities", listEntities) - app.GET("/entities/:id", getEntity) - app.DELETE("/entities/:id", deleteEntity) - - app.Logger.Fatal(app.Start(":8080")) +type WebApplication struct { + echoApp *echo.Echo + entityRepository pkg.EntityRepository } -func formSubmitEntity(ctx echo.Context) error { - entity := pkg.Entity{} - - if err := ctx.Bind(&entity); err != nil { - return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) - } +func NewWebApplication() *WebApplication { + er := pkg.NewEntityMemoryRepository() + er.Init() - if err := entityStorage.Add(&entity); err != nil { - return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) + return &WebApplication{ + echoApp: echo.New(), + entityRepository: er, } - - // TODO: What's the convention when we do form submit. - // return ctx.Redirect(http.StatusTemporaryRedirect, "/website") - return ctx.File("assets/pages/index.html") } -func addEntity(ctx echo.Context) error { - entity := pkg.Entity{} - - if err := ctx.Bind(&entity); err != nil { - return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) - } - - if err := entityStorage.Add(&entity); err != nil { - return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) - } - - return ctx.JSON(http.StatusCreated, entity) +func (wa *WebApplication) Init() { + wa.initAPIRoutes() + wa.initWebsite() } -func updateEntity(ctx echo.Context) error { - entity := pkg.Entity{} - - if err := ctx.Bind(&entity); err != nil { - return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) - } - - if err := entityStorage.Update(&entity); err != nil { - return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) - } - - return ctx.JSON(http.StatusOK, entity) +func (wa *WebApplication) Start(address string) { + wa.echoApp.Logger.Fatal(wa.echoApp.Start(address)) } -func getEntity(ctx echo.Context) error { - entityID := ctx.Param("id") - - entity, err := entityStorage.Get(entityID) - if err != nil { - return ctx.JSON(http.StatusNotFound, pkg.TextResponse{Message: err.Error()}) - } - - if entity == nil { - return ctx.JSON(http.StatusNotFound, pkg.TextResponse{Message: "entity not found"}) - } - - return ctx.JSON(http.StatusOK, entity) -} - -func listEntities(ctx echo.Context) error { - var err error - - page := 1 - - pageStr := ctx.QueryParam("page") - if pageStr != "" { - page, err = strconv.Atoi(pageStr) - if err != nil { - return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) - } - } - - entities, err := entityStorage.List(page, pageSize) - if err != nil { - return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) - } - - return ctx.JSON(http.StatusOK, entities) -} - -func deleteEntity(ctx echo.Context) error { - entityID := ctx.Param("id") - - if err := entityStorage.Delete(entityID); err != nil { - return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) - } +func main() { + wa := NewWebApplication() - return ctx.JSON(http.StatusOK, pkg.TextResponse{Message: "entity deleted"}) + wa.Init() + wa.Start(":8080") } diff --git a/echo/website.go b/echo/website.go new file mode 100644 index 0000000..f99cfcd --- /dev/null +++ b/echo/website.go @@ -0,0 +1,30 @@ +package main + +import ( + "net/http" + + "github.com/CoderVlogger/go-web-frameworks/pkg" + "github.com/labstack/echo/v4" +) + +func (wa *WebApplication) initWebsite() { + wa.echoApp.Static("/static", "assets") + wa.echoApp.File("/", "assets/pages/index.html") // Method: get + wa.echoApp.POST("/", wa.formSubmitEntity) +} + +func (wa *WebApplication) formSubmitEntity(ctx echo.Context) error { + entity := pkg.Entity{} + + if err := ctx.Bind(&entity); err != nil { + return ctx.JSON(http.StatusBadRequest, pkg.TextResponse{Message: err.Error()}) + } + + if err := wa.entityRepository.Add(&entity); err != nil { + return ctx.JSON(http.StatusInternalServerError, pkg.TextResponse{Message: err.Error()}) + } + + // TODO: What's the convention when we do form submit. + // return ctx.Redirect(http.StatusTemporaryRedirect, "/website") + return ctx.File("assets/pages/index.html") +} From 864c942c0d1dceb822d6b86a51fcd4ba3c1abe34 Mon Sep 17 00:00:00 2001 From: Kanan Rahimov Date: Sat, 12 Feb 2022 15:10:22 +0100 Subject: [PATCH 4/6] iris static assets and template --- iris/assets/js/index.js | 1 + iris/assets/pages/index.html | 25 +++++++++++++++++++++++++ iris/server.go | 10 +++++++++- iris/templates/entity-form.html | 22 ++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 iris/assets/js/index.js create mode 100644 iris/assets/pages/index.html create mode 100644 iris/templates/entity-form.html diff --git a/iris/assets/js/index.js b/iris/assets/js/index.js new file mode 100644 index 0000000..8df6f4a --- /dev/null +++ b/iris/assets/js/index.js @@ -0,0 +1 @@ +console.log("demo") \ No newline at end of file diff --git a/iris/assets/pages/index.html b/iris/assets/pages/index.html new file mode 100644 index 0000000..7034cb1 --- /dev/null +++ b/iris/assets/pages/index.html @@ -0,0 +1,25 @@ + + +

Iris

+ +

Submit a new entity:

+ + + + + +

+ + + +

+ + + +

+ + + + + + diff --git a/iris/server.go b/iris/server.go index 42ee22f..3c5ee80 100644 --- a/iris/server.go +++ b/iris/server.go @@ -15,8 +15,16 @@ func main() { app := iris.New() entityStorage.Init() + tmpl := iris.HTML("./templates", ".html") + app.RegisterView(tmpl) + app.Get("/", func(ctx iris.Context) { - ctx.WriteString("Hello, Iris!") + ctx.ServeFile("./assets/pages/index.html") + }) + app.HandleDir("/static", iris.Dir("./assets")) + + app.Get("/entity-form", func(ctx iris.Context) { + ctx.View("entity-form.html") }) booksAPI := app.Party("/entities") diff --git a/iris/templates/entity-form.html b/iris/templates/entity-form.html new file mode 100644 index 0000000..4db8671 --- /dev/null +++ b/iris/templates/entity-form.html @@ -0,0 +1,22 @@ + + + +

Entity Form

+
+ + +

+ + + +

+ + + +

+ + +
+ + + \ No newline at end of file From 7f285c3c94ecaa6a3d897cb43d583e913b6e1d14 Mon Sep 17 00:00:00 2001 From: Kanan Rahimov Date: Sat, 12 Feb 2022 23:26:34 +0100 Subject: [PATCH 5/6] iris template context data --- iris/server.go | 7 +++++++ iris/templates/entity-form.html | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/iris/server.go b/iris/server.go index 3c5ee80..5dbe38f 100644 --- a/iris/server.go +++ b/iris/server.go @@ -24,6 +24,13 @@ func main() { app.HandleDir("/static", iris.Dir("./assets")) app.Get("/entity-form", func(ctx iris.Context) { + ctx.ViewData("message", "Hello world!") + ctx.ViewData("testEntity", pkg.Entity{ + ID: "1001", + Type: pkg.BookEntityType, + Name: "Color", + Description: "Red", + }) ctx.View("entity-form.html") }) diff --git a/iris/templates/entity-form.html b/iris/templates/entity-form.html index 4db8671..ff5f968 100644 --- a/iris/templates/entity-form.html +++ b/iris/templates/entity-form.html @@ -2,6 +2,28 @@

Entity Form

+ +

+ {{.message}} + +

+ +
+

Test Entity

+
+
ID
+
{{.testEntity.ID}}
+ +
Type
+
{{.testEntity.Type}}
+
Name
+
{{.testEntity.Name}}
+
Description
+
{{.testEntity.Description}}
+ +
+
+
From ce49b61c52d5a50f507132d6966ba708371bc3bf Mon Sep 17 00:00:00 2001 From: Kanan Rahimov Date: Tue, 15 Feb 2022 23:51:44 +0100 Subject: [PATCH 6/6] fiber getting started --- fiber/go.mod | 16 +++++++++++++ fiber/go.sum | 24 +++++++++++++++++++ fiber/server.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 fiber/go.mod create mode 100644 fiber/go.sum create mode 100644 fiber/server.go diff --git a/fiber/go.mod b/fiber/go.mod new file mode 100644 index 0000000..072703a --- /dev/null +++ b/fiber/go.mod @@ -0,0 +1,16 @@ +module demoapp + +go 1.17 + +replace github.com/CoderVlogger/go-web-frameworks/pkg => ../pkg + +require ( + github.com/CoderVlogger/go-web-frameworks/pkg v0.0.0-20220207162710-24ad69459d6b // indirect + github.com/andybalholm/brotli v1.0.4 // indirect + github.com/gofiber/fiber/v2 v2.27.0 // indirect + github.com/klauspost/compress v1.14.1 // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect + github.com/valyala/fasthttp v1.33.0 // indirect + github.com/valyala/tcplisten v1.0.0 // indirect + golang.org/x/sys v0.0.0-20220111092808-5a964db01320 // indirect +) diff --git a/fiber/go.sum b/fiber/go.sum new file mode 100644 index 0000000..4703d00 --- /dev/null +++ b/fiber/go.sum @@ -0,0 +1,24 @@ +github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= +github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/gofiber/fiber/v2 v2.27.0 h1:u34t1nOea7zz4jcZDK7+ZMiG+MVFYrHqMhTdYQDiFA8= +github.com/gofiber/fiber/v2 v2.27.0/go.mod h1:0bPXdTu+jRqINrEq1T6mHeVBnE0lQd67PGu35jD3hLk= +github.com/klauspost/compress v1.14.1 h1:hLQYb23E8/fO+1u53d02A97a8UnsddcvYzq4ERRU4ds= +github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.33.0 h1:mHBKd98J5NcXuBddgjvim1i3kWzlng1SzLhrnBOU9g8= +github.com/valyala/fasthttp v1.33.0/go.mod h1:KJRK/MXx0J+yd0c5hlR+s1tIHD72sniU8ZJjl97LIw4= +github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220111092808-5a964db01320 h1:0jf+tOCoZ3LyutmCOWpVni1chK4VfFLhRsDK7MhqGRY= +golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/fiber/server.go b/fiber/server.go new file mode 100644 index 0000000..18ca973 --- /dev/null +++ b/fiber/server.go @@ -0,0 +1,63 @@ +package main + +import ( + "strconv" + + "github.com/gofiber/fiber/v2" + + "github.com/CoderVlogger/go-web-frameworks/pkg" +) + +var ( + pageSize = 4 +) + +func main() { + app := fiber.New() + + entitiesRepo := pkg.NewEntityMemoryRepository() + entitiesRepo.Init() + + app.Get("/", func(c *fiber.Ctx) error { + return c.SendString("Hello, Fiber!") + }) + + entitiesAPI := app.Group("/entities") + entitiesAPI.Get("/", func(c *fiber.Ctx) error { + pageStr := c.Query("page", "1") + page, err := strconv.Atoi(pageStr) + if err != nil { + page = 1 + } + + entities, err := entitiesRepo.List(page, pageSize) + if err != nil { + // c.JSON(pkg.TextResponse{Message: err.Error()}) + // return fiber.NewError(fiber.StatusInternalServerError, err.Error()) + + errMsg := pkg.TextResponse{Message: err.Error()} + return c.Status(fiber.StatusInternalServerError).JSON(errMsg) + } + + c.JSON(entities) + return nil + }) + entitiesAPI.Get("/:id", func(c *fiber.Ctx) error { + entityID := c.Params("id", "") + + entity, err := entitiesRepo.Get(entityID) + if err != nil { + c.JSON(pkg.TextResponse{Message: err.Error()}) + return fiber.ErrInternalServerError + } + + if entity == nil { + return fiber.ErrNotFound + } + + c.JSON(entity) + return nil + }) + + app.Listen(":8080") +}