tros

package module
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

README

Golang Application Level OS Framework Base Library


Table of Contents

Quickstart

Browse this tros example to quickly build your Golang web application.

DirectoryStructure:

  • |--conf: config file management
  • |--contants: configuration file key constants && application level constant definitions
  • |--context: the context encapsulation of the TROS version
  • |--enums: application level enumeration definition
    • |--country: national definition
    • |--currency: money definition
  • |--lang: language definition (may be abandoned in the future)
  • |--logx: application level log management trlogger
  • |--pkg: application level toolkit, including common tool methods and third-party tools
    • |--third_party: third party access methods
    • |--utils: tool based methods
      • |--encrypt: application level encryption and decryption methods
  • |--server: main entrance for launching application level microservices
    • |--grpc: GRPC microservice
    • |--http: HTTP microservice
    • |--middleware: interceptors for GRPC and HTTP
  • |--sys: system level approach
    • |--cmd: command line execution method
    • |--structure: application level data structure
    • |--timer: application level timer
  • |--trerror: application level universal error definition
  • |--trkit: middleware toolkit, including connections and usage of server middleware such as DB and message queues
    • |--mongox: mongodb client
    • |--mysqlx: mysqldb client
    • |--redisx: redisdb client

Explain

  • Adopting grpc gateway technology, supporting both RESTful API and grpc API
  • External access can be done via HTTP
  • GRPC can be used internally for microservice communication
  • Interface Definition Example:
    • Implement interface definition by defining protobuf file
    • The buf command can be used to compile protobuf files into three files: pb.go, pb.gw.go, and _grpc.pb.go
    • Implementing API interfaces in services through the form of 'inheritance'
  syntax = "proto3";
  
  package console.v1;
  
  import "google/api/annotations.proto";
  import "google/protobuf/descriptor.proto";
  import "protoc-gen-openapiv2/options/annotations.proto";
  
  option go_package = "example-server/console/v1";
  
  // XXX api
  service ExampleService {
    // XXXX function
    rpc List(ListRequest) returns (ListResponse) {
      option (google.api.http) = {
        post: "/console/v1/example/list"
        body: "*"
      };
      option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
        tags: ["XXXX desc"]
      };
    }
  }
  
  // ListResponse response
  message ListResponse {
    // XXXX
    int64 total = 2 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "remark desc"}];
  }
  
  // ListRequest request
  message ListRequest {
    // XXXXX
    string id = 1;
  }

DatabaseAccessLayer

The trkit directory provides fast read and write access methods for MySQL, MongoDB and Redis Before use, you need to do the following steps(Taking MySQL as an example):

  • Step 1:Define your. sql file and data table
CREATE TABLE `t_user`
(
    `id`        bigint      NOT NULL AUTO_INCREMENT COMMENT 'primary key',
    `user_name` varchar(64) NOT NULL COMMENT 'username',

) ENGINE=InnoDB DEFAULT COMMENT='user table';
  • Step 2: Compile the CREATE TABLE statement file into Golang code using GTC Tool(Go Table Compiler)
  • Step 3: Copy the generated database access Golang code to your project
  • Step 4: Add MySQL connection parameters to your project configuration file and load them through Golang code
    • such as:
mysql:
  url: root:123456@tcp(127.0.0.1:3306)/example
  maxIdleCons: 5
  maxLife: 3600
  poolSize: 15
  maxIdleTime: 1200
  • Step 5: At this point, you can efficiently start the web server service and read/write databases

Documentation

Overview

Package tros golang OS

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App application

func New

func New(settings ...SettingFunc) *App

func (*App) Init

func (app *App) Init() error

func (*App) Run

func (app *App) Run()

Run application

func (*App) Stop

func (app *App) Stop() error

Stop application

type AppContext

type AppContext interface {
	// HTTPRouter http router
	HTTPRouter() http.Router

	// ServiceRegistrar register grpc service
	ServiceRegistrar() grpc.ServiceRegistrar
}

AppContext app context

type Initializer

type Initializer interface {
	// Init component
	Init(atx AppContext) error
}

Initializer interface with Init func

type Server

type Server interface {
	// Start a server
	Start(ctx context.Context) error
	// Stop a server
	Stop() error
}

Server interface of server

type SettingFunc

type SettingFunc func(*App)

SettingFunc of app

func Servers

func Servers(servers ...Server) SettingFunc

Servers register servers to app

func WithInitializers

func WithInitializers(initializers ...Initializer) SettingFunc

WithInitializers register initializers to app

Directories

Path Synopsis
client
enums
Package lang for globalization
Package lang for globalization
pkg
ip
utils
Package utils add some context function
Package utils add some context function
server
middleware
Package middleware root package of middlewares
Package middleware root package of middlewares
sys
cmd
codes
Package codes provide codes list
Package codes provide codes list
trkit

Jump to

Keyboard shortcuts

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