Skip to content

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

27 Commits

Folders and files

Repository files navigation

BUNAPP-API

This repository serves as an example of a RESTful API written in golang

MODULES

SETUP ENVIRONMENT

Install golang and make binaries.

sudo apt update && sudo apt upgrade
sudo apt install golang makefile

Pull the code to local directory ~/GolandProjects/bunapp-api.

git clone https://github.com/alpha-omega-corp/bunapp-api.git ~/GolandProjects/bunapp-api

Open the project in Goland and install dependencies.

go mod download
go mod tidy

Create a dev config file from the test config file in app/config.

cp ./app/config/test.yaml ./app/config/dev.yaml

Create a dev database from the docker-compose file.

make db_create

Create migrations table for bun.

make db_init

Run the database reset command once to create required tables.

make db_reset

Start the application using the Makefile.

make server

Or manually using go run.

go run cmd/main.go -env=dev server

FEATURES

1. Command line interface

Documentation | GitHub

main.go handles the application's cli commands.

Top levels commands:

go run cmd/main.go -env=dev server
go run cmd/main.go -env=dev db

Database commands:

go run cmd/main.go -env=dev db init
go run cmd/main.go -env=dev db reset

Server commands:

go run cmd/main.go -env=dev server start

2. Bun application package

Documentation | GitHub

The app directory contains the code responsible for creating an app *App instance.

  1. Create a directory example inside github.com/alpha-omega-corp/bunapp-api

  2. From example create a init.go file with the following code:

package example

import (
  "context"
  "github.com/alpha-omega-corp/bunapp-api/app"
)

func Bootstrap() {
  app.OnStart("example.init", func (ctx context.Context, app *app.App) error {
    //app.Router()
    //app.ApiRouter()
    //app.Database()
    //app.Repositories()
    //app.GptClient()
    //app.PromptManager()
  })
}

Example: api-app

The callback function gives you access to the app *App instance

To start the example application call the public Bootstrap function from the cmd/main.go file.

package main

import (
    "github.com/alpha-omega-corp/bunapp-api/example"
)

func main() {
	//...
    Action:
        func(c *cli.Context) error {
            example.Bootstrap()
        } //...
}

Example: cmd/main.go

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

⌂ 换网址