Page MenuHomeHexavara Tech

[!] Create Your First Crema Project
Updated 1,864 Days AgoPublic

  1. Create new go project folders

new_project
\__ bin
\__ pkg
\__ src
\__ \__ conf

  1. Create main.go inside src directory
cd src
touch main.go
  1. Run inside src
go get github.com/gadp22/crema
  1. Create db.json under src/conf
cd conf
touch db.json
  1. Add to db.json
{
    "db" : {
        "driver" : "psql/mysql", //choose one
        "host" : "localhost",
        "port" : "5432",
        "user" : "postgres",
        "pass" : "postgres",
        "dbname" : "database"
    }
}
  1. 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))
}
  1. Run
go build
Last Author
galang
Last Edited
Oct 15 2019, 3:26 PM

Event Timeline

galang moved this document from Restricted Phriction Wiki DocumentOct 13 2019, 8:29 PM
galang changed the title from Init Crema Server to [!] Create Your First Crema Project.Oct 15 2019, 3:26 PM