Skip to content

Instantly share code, notes, and snippets.

View Bebbolus's full-sized avatar

Roberto Bebbolus

View GitHub Profile
@Bebbolus
Bebbolus / smtp-gmail-send.go
Created May 8, 2019 13:22 — forked from jpillora/smtp-gmail-send.go
Send email using Go (Golang) via GMail with net/smtp
package main
import (
"log"
"net/smtp"
)
func main() {
send("hello there")
}
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 {
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)
//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
//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"`
{
"endpoints":[
{
"path":"/myroute",
"handler":"./plugins/controllers/general.so",
"middlewares":[
{
"handler":"./plugins/middlewares/method.so",
"params":"GET|POST"
}
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) {
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
package main
import (
"os"
"fmt"
"plugin"
)
//define a local interface of what you want to get from plugin symbol
type MyPlug interface {
Talk()
package main
import "fmt"
type myPlugin string
func (h myPlugin) Talk() {
fmt.Println("Hello FROM PLUGIN!!!")
}