nova

package module
v0.0.0-...-d391ba0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 14 Imported by: 0

README

Nova

基于Golang的轻量级API框架

dbtest

特性

  • 支持平滑重启
  • 路由自动注册
  • 编码友好的Orm查询,无需字段映射,无需定义返回结构体
  • 请求参数自动校验及数据类型转换
  • 请求无需传递Context
  • PHP开发者熟悉的异常处理
  • 低侵入性设计,现有struct一行代码即可对外服务
  • 一键初始化项目,快速开发
  • 支持中间件
  • 低耦合模块化设计

快速上手

创建 go.mod

module api

go 1.17

安装依赖

go get github.com/boyxp/nova

创建 hello.go

package main

import "github.com/boyxp/nova"
import "github.com/boyxp/nova/router"

func main() {
   router.Register(&Hello{})
   nova.Listen("9800").Run()
}

type Hello struct {}
func (h *Hello) Hi(name string) map[string]string {
   return map[string]string{"name":"hello "+name}
}

启动

go run hello.go &

POST请求接口

curl -X POST -d 'name=eve' 127.0.0.1:9800/hello/hi

项目模式

初始化项目
$ curl https://raw.githubusercontent.com/boyxp/nova/master/init.sh | sh

默认创建 _demo 目录,可以改名为项目目录,直接初始化git

进程管理

启动进程

sh manage.sh start

查看进程状态

sh manage.sh status

平滑重启(执行build,重启过程旧请求不中断)

sh manage.sh restart

重新加载配置(不执行build,只重新加载环境变量配置)

sh manage.sh reload

停止进程(将在请求完成后退出)

sh manage.sh stop
创建控制器

进入 controller 目录,创建struct,并将struct注册到路由

package controller

import "github.com/boyxp/nova/router"
func init() {
   router.Register(&Hello{})
}

type Hello struct {}
func (h *Hello) Hi(name string) map[string]string {
	return map[string]string{"name":"hello "+name}
}
测试运行

重启进程

sh manage.sh restart

POST请求接口

curl -X POST -d 'name=eve' 127.0.0.1:9800/hello/hi

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run()

Types

type App

type App struct {
	Port     string
	Request  request.Interface
	Response response.Interface
	// contains filtered or unexported fields
}

func Listen

func Listen(port string) *App

func (*App) Catch

func (A *App) Catch()

异常捕获

func (*App) Handle

func (A *App) Handle() http.Handler

func (*App) Run

func (A *App) Run()

func (*App) ServeHTTP

func (A *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*App) SetRequest

func (A *App) SetRequest(req request.Interface) *App

func (*App) SetResponse

func (A *App) SetResponse(res response.Interface) *App

func (*App) Use

func (A *App) Use(next func(next http.Handler) http.Handler) *App

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL