summaryrefslogtreecommitdiff
path: root/api/exampleReq.go
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-03-13 06:47:19 +0530
committersinanmohd <sinan@sinanmohd.com>2024-03-15 22:20:15 +0530
commit3dd390c0cb56ffb5a7c1f94afaed0b80ad12cbe1 (patch)
treed14983bb19b66f3a8c69e8d9ca8dbea296a80df0 /api/exampleReq.go
repo: init
Diffstat (limited to 'api/exampleReq.go')
-rw-r--r--api/exampleReq.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/api/exampleReq.go b/api/exampleReq.go
new file mode 100644
index 0000000..d4ec862
--- /dev/null
+++ b/api/exampleReq.go
@@ -0,0 +1,59 @@
+package api
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+
+ redqdb "sinanmohd.com/redq/db"
+)
+
+type examplApiName struct {
+ db *redqdb.SafeDB
+ req *RequestApiName
+ resp *ResponseApiName
+}
+
+type RequestApiName struct {
+ BearerToken string
+}
+
+type ResponseApiName struct {
+ Bearer *redqdb.Bearer
+ Error string
+}
+
+func newExamplApiName(db *redqdb.SafeDB) *examplApiName {
+ a := &examplApiName{}
+ a.db = db
+
+ return a
+}
+
+func (a *examplApiName) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
+ a.req = &RequestApiName{}
+ a.resp = &ResponseApiName{}
+ a.resp.Bearer = &redqdb.Bearer{}
+
+ err := unmarshal(r.Body, a.req)
+ if err != nil {
+ log.Println(err)
+ return
+ }
+
+ err = a.resp.Bearer.VerifyAndUpdate(a.db, a.req.BearerToken)
+ if err != nil {
+ log.Println(err)
+ a.resp.Error = err.Error()
+ return
+ }
+
+ json, err := marshal(a.resp)
+ if err != nil {
+ log.Println(err)
+ a.resp.Error = err.Error()
+ return
+ }
+
+ fmt.Fprintf(rw, json)
+}