gocroot

GoCroot: Greatly Optimized Cloud Resource Operation and Orchestration Transformer

Unlock the Full Potential of Cost-Effective Cloud Infrastructure

Elevate your cloud operations with GoCroot, the ultimate solution for businesses and developers seeking high performance and cost-efficiency. Designed to optimize backend infrastructure, GoCroot streamlines resource management and orchestration, ensuring seamless scalability and reduced overhead.

🚀 Ready to scale efficiently? Try GoCroot today!


GoCroot Modes

We offer two production modes tailored for different platforms:

  1. Net HTTP-Based
  2. Fiber-Based

Type Declaration in Go

In Go, data structures are defined as struct. Here’s an example:

type Example struct {
	ID       primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty" query:"id" url:"_id,omitempty" reqHeader:"token"`
	Messages string             `json:"messages" bson:"messages" query:"messages" url:"messages" reqHeader:"token"`
}

Explanation of Tags:

Quick struct declaration:

var request struct {
   Token string `json:"token"`
}

Routing with Net HTTP

Define routes in a simple switch statement. Example:

With URL Parameter

case method == "POST" && at.URLParam(path, "/webhook/nomor/:nomorwa"):
	controller.PostInboxNomor(w, r)

Without URL Parameter

case method == "GET" && path == "/data/phone/all":
	controller.GetBotList(w, r)

Controller Implementation

Controllers handle API logic. Below is a sample for Net HTTP and Fiber:

Net HTTP Example

func Homepage(w http.ResponseWriter, r *http.Request) {
	// Your logic here
}

Common Operations:

Return JSON Response:

at.WriteJSON(w, http.StatusOK, Example)

Fiber Example

func Homepage(ctx *fiber.Ctx) error {
	// Your logic here
	return ctx.Status(fiber.StatusOK).JSON(fiber.Map{"message": "success"})
}

Common Operations:

Return JSON Response:

return ctx.Status(fiber.StatusOK).JSON(fiber.Map{"status": "success"})

MongoDB Integration

Easily log or manage documents in MongoDB:

Insert Document without Struct:

document := bson.D{
    {Key: "username", Value: "user1"},
    {Key: "createdAt", Value: time.Now()},
}

Convert ObjectID:


Testing and Code Coverage

Ensure code quality with Go’s built-in testing tools.

  1. Write Test Cases:
    main_test.go
    func TestSum(t *testing.T) {
        result := Sum(2, 3)
        if result != 5 {
            t.Errorf("Expected 5, got %d", result)
        }
    }
    
  2. Run Tests with Coverage:
    go test -cover
    
  3. Generate Detailed Report:
    go test -coverprofile=coverage.out
    go tool cover -html=coverage.out
    

Deployment

Set up your Go environment:

export GOPROXY=proxy.golang.org

Update dependencies and publish packages:

go get -u all
go mod tidy
git tag v0.1.0
git push origin --tags

Deploy your application following our deployment guide.