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 main | |
import ( | |
"log" | |
"net/smtp" | |
) | |
func main() { | |
send("hello there") | |
} |
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
for _, mid := range v.Middlewares { | |
//load middleware plugin | |
plug, midErr := plugin.Open(mid.Handler) | |
if midErr != nil { | |
log.Fatalf(midErr) | |
os.Exit(-1) | |
} | |
//look up the Middleware type | |
symMiddleware, midErr := plug.Lookup("Middleware") | |
if midErr != nil { |
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
for _, v := range RoutesConf.Endpoints { | |
//load module: | |
plug, err := plugin.Open(v.Controller) | |
if err != nil { | |
kill(err) | |
} | |
//look up for an exported Controller type | |
symController, err := plug.Lookup("Controller") | |
if err != nil { | |
kill(err) |
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
//ReadFromJSON function load a json file into a struct or return error | |
func ReadFromJSON(t interface{}, filename string) error { | |
jsonFile, err := ioutil.ReadFile(filename) | |
if err != nil { | |
return err | |
} | |
err = json.Unmarshal([]byte(jsonFile), t) | |
if err != nil { | |
log.Fatalf("error: %v", err) | |
return err |
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
//source routes configuration struct to load from the json configuration file | |
type routes struct { | |
Endpoints []struct { | |
Controller string `json:"controller"` | |
Middlewares []struct { | |
Handler string `json:"handler"` | |
Params string `json:"params"` | |
} `json:"middlewares"` | |
Path string `json:"path"` | |
} `json:"endpoints"` |
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
{ | |
"endpoints":[ | |
{ | |
"path":"/myroute", | |
"handler":"./plugins/controllers/general.so", | |
"middlewares":[ | |
{ | |
"handler":"./plugins/middlewares/method.so", | |
"params":"GET|POST" | |
} |
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 main | |
import ( | |
"net/http" | |
"strings" | |
) | |
type middleware string | |
func (m middleware) Pass(args string) func(http.HandlerFunc) http.HandlerFunc { | |
return func(f http.HandlerFunc) http.HandlerFunc { | |
// Define the http.HandlerFunc | |
return func(w http.ResponseWriter, r *http.Request) { |
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 main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
type controller string | |
func (h controller) Fire(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello FROM CONTROLLER PLUGIN!!!") | |
} | |
// Controller exported namevar |
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 main | |
import ( | |
"os" | |
"fmt" | |
"plugin" | |
) | |
//define a local interface of what you want to get from plugin symbol | |
type MyPlug interface { | |
Talk() |
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 main | |
import "fmt" | |
type myPlugin string | |
func (h myPlugin) Talk() { | |
fmt.Println("Hello FROM PLUGIN!!!") | |
} |
NewerOlder