Created
December 12, 2017 04:39
-
-
Save aprimadi/cbd1377c16cba025a777be59361cefdc to your computer and use it in GitHub Desktop.
Routers function demonstrating NoProtect middleware usage for testing purpose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import ( | |
"net/http" | |
"github.com/bouk/httprouter" | |
"github.com/dexcodeinc/nosurfctx" | |
) | |
var Routers *httprouter.Router | |
var CSRF func (h http.HandlerFunc) http.HandlerFunc | |
func LoadRouters(test bool) { | |
r := httprouter.New() | |
if test == true { | |
CSRF = nosurfctx.NoProtect | |
} else { | |
CSRF = nosurfctx.Protect | |
} | |
// Static | |
r.GET("/", CSRF(Home)) | |
r.GET("/gadai-emas", CSRF(PawnGold)) | |
r.GET("/syarat-dan-ketentuan", CSRF(TermsAndConditions)) | |
// API | |
r.POST("/prospect_loan_items", CSRF(ProspectLoanItemCreate)) | |
// Admin | |
r.GET("/admin/login", CSRF(AdminLogin)) | |
r.GET("/admin/logout", CSRF(AdminSessionDestroy)) | |
r.POST("/admin/session", CSRF(AdminSessionCreate)) | |
r.GET("/admin/prospect_loan_items", CSRF(AdminProspectLoanItems)) | |
r.GET("/admin/prospect_loan_items/search", CSRF(AdminProspectLoanItemsSearch)) | |
r.GET("/admin/loan_items", CSRF(AdminLoanItems)) | |
r.GET("/admin/loan_items/search", CSRF(AdminLoanItemsSearch)) | |
r.GET("/admin/loan_items/show/:id", CSRF(AdminLoanItemsShow)) | |
r.GET("/admin/loan_items/pay/:id", CSRF(AdminLoanItemsPay)) | |
r.POST("/admin/loan_items/pay/:id", CSRF(AdminLoanItemsPay)) | |
r.GET("/admin/loan_items/new", CSRF(AdminLoanItemsNew)) | |
r.POST("/admin/loan_items", CSRF(AdminLoanItemsCreate)) | |
r.NotFound = http.FileServer(http.Dir("static")) | |
Routers = r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment