cin

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

GitHub tag (latest by date) GitHub go.mod Go version GitHub last commit

cin

简体中文

The http and websocket server's framework.

Inspiration come form yii2.

Getting started

Edit file: main.go

package main

import (
    "github.com/cinling/cin"
    "github.com/cinling/cin/base"
)

func main() {
	config := cin.NewConfig()
    config.ComponentDict = map[string]base.ConfigComponentInterface{
        "ws":      cin.NewConfigWebsocketServer(24600),
        "http":    cin.NewConfigHttpServer(24601).SetSessionName("test"),
        "db":      cin.NewConfigDatabase("mysql", "127.0.0.1", "3306", "cin", "root", "root"),
        "console": cin.NewConfigConsole(),
    }
    cin.App.AddConfig(config)
    cin.App.Run()
}

Run go module to download dependency.

go mod tidy

Compiled code.

go build main.go

Run bin file

  • on windows

./main.exe

  • on linux

./main

Migrations

After Compiled code, run the following command to create migration's file.

Documentation

Index

Constants

View Source
const (
	ComponentWebsocketServer = constants.ComponentWebsocketServer

	// 应用状态:初始化
	ApplicationStatusInit = constants.ApplicationStatusInit
	// 应用状态:开始(启动中)
	ApplicationStatusStart = constants.ApplicationStatusStart
	// 应用状态:即将停止
	ApplicationStatusStop = constants.ApplicationStatusStop

	// websocket server 运行模式:自动处理【推荐】
	// 使用框架内规定的 Handler 或 BaseController 自动匹配对应的方法。发送数据必须是规范的数据。
	// 使用该模式依然可以使用 OnMessage 接收数据。但是不能发送数据
	WebsocketServerModeAutoHandler = constants.WebsocketServerModeAutoHandler
	// websocket server 运行模式:自定义处理。
	// 自定义 OnMessage 回调方法发送数据。根据实际需求自定义数据返回
	WebsocketServerModeCustom = constants.WebsocketServerModeCustom

	// 控制器类型:websocket
	ControllerTypeWebsocket = constants.ControllerTypeWebsocket
	// 控制器类型:http
	ControllerTypeHttp = constants.ControllerTypeHttp
)

Variables

View Source
var App = newApplication()

应用全局实例(只需要一个实例即可操作整个应用)

Functions

func NewConfigConsole added in v0.0.2

func NewConfigConsole() *configs.Console

新建 控制台配置

func NewConfigDatabase added in v0.0.2

func NewConfigDatabase(driverName string, host string, port string, name string, username string, password string) *configs.Database

新建 数据库配置

func NewConfigHttpServer added in v0.0.2

func NewConfigHttpServer(port uint16) *configs.HttpServer

新建 http server 配置

func NewConfigWebsocketServer added in v0.0.2

func NewConfigWebsocketServer(port uint16) *configs.WebsocketServer

新建 websocket server 配置

Types

type BaseController added in v0.0.2

type BaseController struct {
	models.BaseController
}

基础 websocket 处理器

type Config

type Config struct {
	models.Config
}

配置类

func NewConfig

func NewConfig() *Config

新建配置

Directories

Path Synopsis
console
test

Jump to

Keyboard shortcuts

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