Phriction Knowledge Center - Hexavara Technology Crema Framework [!] Create Your First Crema Project
[!] Create Your First Crema Project
[!] Create Your First Crema Project
- Create new go project folders
new_project
\__ bin
\__ pkg
\__ src
\__ \__ conf
- Create main.go inside src directory
cd src touch main.go
- Run inside src
go get github.com/gadp22/crema
- Create db.json under src/conf
cd conf touch db.json
- Add to db.json
{ "db" : { "driver" : "psql/mysql", //choose one "host" : "localhost", "port" : "5432", "user" : "postgres", "pass" : "postgres", "dbname" : "database" } }
- Add to main.go
package main import ( "log" "net/http" crema "./github.com/gadp22/crema" ) func hello(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello World!")) } func main() { server := crema.InitServer() server.AddRoutes(http.MethodGet, "/hello", hello) crema.LogPrintf("[MAIN] Server is running, listening to port 8001 ....") log.Fatal(http.ListenAndServe(":8001", server.Router)) }
- Run
go build
Tags
None
Subscribers
None
- Last Author
- • galang
- Last Edited
- Oct 15 2019, 3:26 PM