framework

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

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

Go to latest
Published: Feb 4, 2021 License: MIT Imports: 18 Imported by: 0

README

配置文件 请使用 toml , yml 嵌套读取存在问题.

初始化

framework.InitConfig(config.InitCfg)


// 监听端口 默认 8080
framework.RunWeb(route.RegisterRouter)

目录结构

config
 -| config.go
 -| repo
    -| repo.go

代码

// config.go
package config

import (
	cfg "gitee.com/whmmm/go-web-framework/config"
)

var (
	// 系统配置信息 , 要读取的配置文件信息
	App = &_Config{
		Config: &cfg.Config{},
	}
	// 初始化信息
	InitCfg = &cfg.InitConfigStruct{
		Config: App,
		DbConfigs: &cfg.DbConfigs{
			{Database: repo.Master, DbConfig: &App.Master},
		},
	}
)

type _Config struct {
	*cfg.Config
}

// repo.go 当作一个 facade 
package repo

import "gorm.io/gorm"

var (
	Master = new(gorm.DB)
)


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultGinEngine

func DefaultGinEngine() *gin.Engine

创建一个默认的 gin.Engine

创建完毕后,手动启用

 port := app.Config.Server.Port
	if port == 0 {
		port = 8080
	}

	// 文件上传目录

	// 启用 gzip
	r.Use(gzip.Gzip(gzip.DefaultCompression))
	err := r.Run(fmt.Sprintf(":%v", port)) // listen and serve on 0.0.0.0:8080
	if err != nil {
		logger.Error(err)
		panic(err)
	}

func InitConfig deprecated

func InitConfig(cfg types.Any)

初始化 系统变量...

cfg must be a ptr.

Deprecated: 推荐使用 InitConfigWithFunc

func InitConfigWithFunc

func InitConfigWithFunc(cfg types.Any, entry func())

初始化 系统变量...

cfg must be a ptr.

func InitTest

func InitTest(cfg types.Any)

测试时使用的方法初始化 config 配置文件

cfg 必须是指针

func RunEmpty

func RunEmpty(routeFunc func(router *gin.Engine))

运行一个空路由

func RunFunc

func RunFunc(entry func())

等待初始化后执行该方法

func RunWeb

func RunWeb(routeFunc func(router *gin.Engine))

主方法, 会阻塞主线程 . param: routeFunc 注册路由的方法

Types

This section is empty.

Directories

Path Synopsis
由于没有泛型, 每个类型都需要手动添加方法...
由于没有泛型, 每个类型都需要手动添加方法...

Jump to

Keyboard shortcuts

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