taurus

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: BSD-2-Clause Imports: 10 Imported by: 0

README

Taurus GoDoc

 _(_____)_
|__.___.__|
    | |
    | |
    |_|

Introduction

Simplify and Accelerate Your Development Process. Taurus is designed to provide developers with a simplified and efficient solution for building HTTP services and leveraging various utility libraries. With our framework, you can embark on rapid development journeys, ensuring both simplicity and efficiency throughout the entire process.

Documentation

To be updated...

Requirements

  • Go version >= 1.18

Quick Start

  1. Config file:
[taurus_server_http]
    Host = "0.0.0.0"
    Port = 8090
[taurus_log_default]
    Level = "debug"
    FileName = "./taurus.log"
    MaxBackups = 1
    MaxSizeInMB = 10 #dd
    Compress = true
    LocalTime = true
  1. Example code:
package main

import (
	"fmt"
	"time"
	log "github.com/eric-tech01/simple-log"
	sjson "github.com/eric-tech01/simple-json"
	"github.com/eric-tech01/taurus"
	"github.com/eric-tech01/taurus/server"
	"github.com/gin-gonic/gin"
)

type Engine struct {
	taurus.Application
}

func main() {
	eng := &Engine{}
	if err := eng.Startup(
		eng.printLog,
		eng.serverHttp,
	); err != nil {
		panic(err)
	}
	eng.Run()
}

type PostStruct struct {
	Level int `json:"level"`
}

func (eng *Engine) serverHttp() error {
	fmt.Println("start server http")
	s := server.New()

	diag := s.Group("/taurus/diagnoise")

	diag.POST("/setLevel", func(ctx *gin.Context) {
		l := &PostStruct{}
		if err := ctx.Bind(l); err != nil {
			log.Error(err)
			return
		}
		rsp := sjson.New()
		rsp.Set("level", l.Level)
		log.Infof("set level %d", l.Level)
		ctx.JSON(200, rsp)
	})

	diag.GET("/status", func(ctx *gin.Context) {
		ctx.JSON(200, "normal")
	})
	diag.GET("/version", func(ctx *gin.Context) {
		ctx.JSON(200, "normal")
	})

	return eng.Serve(*s)
}

func (eng *Engine) printLog() error {
	go func() {
		for {

			log.Infof("info ....")
			log.Debugf("debuf ....")
			log.Warnf("warn ....")
			log.Errorf("error ....")
			time.Sleep(3 * time.Second)
		}
	}()
	return nil
}
  1. Run code
 go run ./main.go --config=config.toml

Bugs and Feedback

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	HideBanner bool
	// contains filtered or unexported fields
}

func (*Application) Run

func (app *Application) Run() error

Run run application

func (*Application) Serve

func (app *Application) Serve(s server.Server) error

Serve start server

func (*Application) Startup

func (app *Application) Startup(fns ...func() error) error

Startup ..

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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