Phriction Knowledge Center - Hexavara Technology Crema Framework [!] Create Your First Crema Project History Version 1 vs 2
Version 1 vs 2
Version 1 vs 2
Content Changes
Content Changes
1. Create new go project folders
new_project
\__ bin
\__ pkg
\__ src
\__ \__ conf
2. Create main.go inside src directory
```
cd src
touch main.go
```
3. Run inside src
```
go get github.com/gadp22/crema
```
4. Create db.json under src/conf
```
cd conf
touch db.json
```
6. Add to db.json
```
{
"db" : {
"driver" : "psql/mysql", //choose one
"host" : "localhost",
"port" : "5432",
"user" : "postgres",
"pass" : "postgres",
"dbname" : "database"
}
}
```
5. 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))
}
```
6. Run
```
go build
```
1. Create new go project folders
new_project
\__ bin
\__ pkg
\__ src
\__ \__ conf
2. Create main.go inside src directory
```
cd src
touch main.go
```
3. Run inside src
```
go get github.com/gadp22/crema
```
4. Create db.json under src/conf
```
cd conf
touch db.json
```
6. Add to db.json
```
{
"db" : {
"driver" : "psql/mysql", //choose one
"host" : "localhost",
"port" : "5432",
"user" : "postgres",
"pass" : "postgres",
"dbname" : "database"
}
}
```
5. 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))
}
```
6. Run
```
go build
```
1. Create new go project folders
new_project
\__ bin
\__ pkg
\__ src
\__ \__ conf
2. Create main.go inside src directory
```
cd src
touch main.go
```
3. Run inside src
```
go get github.com/gadp22/crema
```
4. Create db.json under src/conf
```
cd conf
touch db.json
```
6. Add to db.json
```
{
"db" : {
"driver" : "psql/mysql", //choose one
"host" : "localhost",
"port" : "5432",
"user" : "postgres",
"pass" : "postgres",
"dbname" : "database"
}
}
```
5. 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))
}
```
6. Run
```
go build
```