Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lancet
/
kvcache
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0e26ff4e
authored
Aug 23, 2019
by
lancet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic routing
parent
324001f1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
kvcache
+0
-0
main.go
+44
-0
No files found.
kvcache
0 → 100755
View file @
0e26ff4e
File added
main.go
View file @
0e26ff4e
package
main
package
main
import
(
"fmt"
"net/http"
"github.com/gorilla/mux"
)
type
Route
struct
{
URL
string
Methods
[]
string
Handler
func
(
http
.
ResponseWriter
,
*
http
.
Request
)
}
func
getValue
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
id
:=
vars
[
"id"
]
resp
:=
fmt
.
Sprintf
(
"Get ID: %s
\n
"
,
id
)
fmt
.
Fprint
(
w
,
resp
)
}
func
delValue
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
id
:=
vars
[
"id"
]
resp
:=
fmt
.
Sprintf
(
"Delete ID: %s
\n
"
,
id
)
fmt
.
Fprint
(
w
,
resp
)
}
func
initRouter
(
router
*
mux
.
Router
,
routes
[]
Route
)
{
for
_
,
i
:=
range
routes
{
for
_
,
j
:=
range
i
.
Methods
{
router
.
HandleFunc
(
i
.
URL
,
i
.
Handler
)
.
Methods
(
j
)
}
}
return
}
func
main
()
{
func
main
()
{
router
:=
mux
.
NewRouter
()
routing
:=
[]
Route
{
{
"/storage/{id}"
,
[]
string
{
"GET"
},
getValue
},
}
initRouter
(
router
,
routing
)
http
.
Handle
(
"/"
,
router
)
fmt
.
Println
(
"Listening"
)
http
.
ListenAndServe
(
":8881"
,
nil
)
return
return
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment