Mhithrandir/go-cms

Handler instead of HandleFunc ?

Opened this issue · 1 comments

Spuxy commented

a.Func = vett[2]

Just saying if its much better to use handler and parse all stuffs by urself instead of let http pkg to decide which methos invoke ?

I didnt read all codes i was just clicking thru codebase but it seems like overwhelming, using make allocation, appends with slice of slice ([:10] etc..) for just sanitize url params/queries

Hello, thanks this comment. first af all I'm learning golang so there is probably thousand of thing I can improve in this code.

I'm not sure I hunderstand what you mean with this issue, in case I've missed the point please correct me.

The logic for the customrequest is that:
instead of creating a main.go full of "handlefunc (xxx, package.func)" I just put a switch with every package, and each package has a method "ParseRequest" that is responsable to handle the request so the main.go is more clean and you don't have to chage it every time you change\add\delete a func.

Example:
in the main.go
switch request.Package {
case "package1":
package1.ParseRoute(request)
case "package2":
package2.ParseRoute(request)
...
}

in each package
//ParseRoute handle the func specified in the apirequest
func ParseRoute(request customrequest.CustomRequest) {
switch request.Func {
case "func1":
Func1(request)
case "func2":
Func3(request)
...
}
}