diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-27 10:36:15 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-27 10:36:15 +0800 |
| commit | a52afde13b4e483e5dd96c7d1a3ace81ce400103 (patch) | |
| tree | f4914a5e788417cddf9ee039ce1a205141c1f7f8 /api.go | |
| parent | a555355d69a4fe9cd01d8bea86ce5b057cd1cd66 (diff) | |
feat: get router working properly and implement basic methods
Diffstat (limited to 'api.go')
| -rw-r--r-- | api.go | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -1,18 +1,35 @@ package growel import ( - + "net/http" ) -type growel struct { } +type Api struct { + router *Router +} + +func New() *Api { + var a Api + a.router = NewRouter() + return &a +} + +func (api *Api) Start(port string) { + http.ListenAndServe(port, api.router) +} -func (growel) New() (*growel) { - return &growel{} +func (api *Api) GET(path string, h Handler) { + api.router.Add("GET", path, h) } -func (*growel) GET() {} -func (*growel) POST() {} -func (*growel) PUT() {} -func (*growel) DELETE() {} +func (api *Api) POST(path string, h Handler) { + api.router.Add("POST", path, h) +} -func (*growel) Start() {} +func (api *Api) PUT(path string, h Handler) { + api.router.Add("PUT", path, h) +} + +func (api *Api) DELETE(path string, h Handler) { + api.router.Add("DELETE", path, h) +} |
