// Copyright 2021 Harran Ali . All rights reserved. // Copyright (c) 2024 Zeni Kim // Use of this source code is governed by MIT-style // license that can be found in the LICENSE file. package core type Route struct { Method string Path string Controller Controller Middlewares []Middleware } type Router struct { Routes []Route } var router *Router func NewRouter() *Router { router = &Router{ []Route{}, } return router } func ResolveRouter() *Router { return router } func (r *Router) Get(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: GET, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) Post(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: POST, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) Delete(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: DELETE, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) Patch(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: PATCH, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) Put(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: PUT, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) Options(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: OPTIONS, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) Head(path string, controller Controller, middlewares ...Middleware) *Router { r.Routes = append(r.Routes, Route{ Method: HEAD, Path: path, Controller: controller, Middlewares: middlewares, }) return r } func (r *Router) GetRoutes() []Route { return r.Routes }