Categorygithub.com/hive-go/hive
modulepackage
1.0.8
Repository: https://github.com/hive-go/hive.git
Documentation: pkg.go.dev

# README

Hive

Hive is an NestJS inspired web framework built on top of Fiber and Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.


⚙️ Installation

go mod init github.com/your/repo

To learn more about Go modules and how they work, you can check out the Using Go Modules blog post.

After setting up your project, you can install Hive with the go get command:

go get -u github.com/hive-go/hive

This command fetches the Hive package and adds it to your project's dependencies, allowing you to start building your web applications with Hive.

⚡️ Quickstart

Getting started with Hive is easy. Here's a basic example to create a simple web server. This example demonstrates initializing a new Fiber app, setting up a route for user, and starting the server.

Suggestion folder structure

src
 ├── modules
 │   └── user
 │       ├── user.module.go
 │       ├── user.controller.go
 │       └── user.service.go
 ├── main.go
 ├── go.mod
 └── go.sum

main.go

package main

import (
	"github.com/your/repo/src/modules/user"
	"github.com/hive-go/hive"
)

func main() {
	app := hive.New()

	app.AddModule(user.UserModule)

	app.Listen("3000")
}

src/modules/user/user.module.go

package user

import (
	"github.com/hive-go/hive"
)

var UserModule = hive.CreateModule()

func init() {
	UserModule.AddController(UserController)
}

src/modules/user/user.controller.go

package user

import (
	"github.com/hive-go/hive"
)

var UserController = hive.CreateController()

func init() {
	UserController.Get("/user", func(c *hive.Ctx) any {
		return UserService.GetUser("123")
	})

	UserController.Post("/user", func(c *hive.Ctx) any {
		return UserService.CreateUser(c)
	})

	UserController.Put("/user", func(c *hive.Ctx) any {
		return UserService.UpdateUser(c)
	})

	UserController.Delete("/user", func(c *hive.Ctx) any {
		return UserService.DeleteUser(c)
	})
}

src/modules/user/user.service.go

package user

import (
	"github.com/hive-go/hive"
)

type UserServiceT struct{}

var UserService = UserServiceT{}

func (u *UserServiceT) GetUser(id string) hive.Map {
	return hive.Map{
		"user": hive.Map{"name": "John Doe"},
	}
}

func (u *UserServiceT) CreateUser(c *hive.Ctx) string {
	return "User Created"
}

func (u *UserServiceT) UpdateUser(c *hive.Ctx) string {
	return "User Updated"
}

func (u *UserServiceT) DeleteUser(c *hive.Ctx) string {
	return "User Deleted"
}

⚙️ Using Hive CLI to Work Faster

go install github.com/hive-go/hive-cli/

⚡️ Quickstart

Getting started with Hive Cli is easy. Here's a basic example to create User Module

  hive-cli generate_resource user

Result in folder structure


 ├── src
 │   └── modules
 │       └── user
 │           ├── user.module.go
 │           ├── user.controller.go
 │           └── user.service.go
 ├── main.go
 ├── go.mod
 └── go.sum
📚 Show more code examples

This simple server is easy to set up and run. It introduces the core concepts of Hive: app initialization, route definition, and starting the server. Just run this Go program, and visit http://localhost:3000/user in your browser to see the message.

📚 Show more code examples

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

Version of current hive package.

# Variables

No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author