/
plug1.go
37 lines (28 loc) · 841 Bytes
/
plug1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"database/sql"
"fmt"
"net/http"
"github.com/CanadianCommander/MicroWeb/pkg/pluginUtil"
"github.com/CanadianCommander/MicroWeb/pkg/templateHelper"
_ "github.com/mattn/go-sqlite3"
)
type FOOBAR struct {
Msg string
}
func HandleRequest(req *http.Request, res http.ResponseWriter, fsName string) bool {
foobar := FOOBAR{"FOO-BAR"}
templateHelper.ProcessTemplateHTML(pluginUtil.ReadFileToBuff(fsName), res, foobar)
return true
}
func HandleVirtualRequest(req *http.Request, res http.ResponseWriter) bool {
db, err := sql.Open("sqlite3", "test.db")
defer db.Close()
if err != nil {
fmt.Printf("FAIL\n\n")
}
db.Exec("CREATE TABLE IF NOT EXISTS foobar (foo text, bar text);")
db.Exec("insert into foobar values (\"hello\", \"world\");")
fmt.Fprint(res, "HELLO FROM AN API FUNCTION!")
return true
}