Giter Site home page Giter Site logo

msn217 / thinkgo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andeya/faygo

0.0 2.0 0.0 18.12 MB

ThinkGo 是一款 Go 语言编写的 web 快速开发框架。它基于开源框架 echo 进行二次开发,旨在实现一种类 ThinkPHP 的高可用、高效率的 web 框架。

Go 100.00%

thinkgo's Introduction

#ThinkGo Web Framework GoDoc

ThinkGo Admin

ThinkGo 是一款 Go 语言编写的 web 快速开发框架。它基于开源框架 echo 进行二次开发,旨在实现一种类 ThinkPHP 的高可用、高效率的 web 框架。在此感谢 echo。它最显著的特点是模块、控制器、操作三层架构的 MVC 架构及其智能路由。再加上对中间件及前端主题的支持,令开发变得异常简单与灵活。

  • 官方QQ群:Go-Web 编程 42730308 Go-Web 编程群

ThinkGo Admin

ThinkGo Admin

##目录结构

├─core 框架目录
│ 
├─main.go 主文件
│ 
├─application 应用模块目录
│  ├─common 公共模块目录
│  │  ├─template.go 模板函数
│  │  ├─common.go 公共变量与函数
│  │  ├─controller 公共控制器类目录
│  │  ├─middleware 中间件目录
│  │  └─model 公共数据模型目录
│  │  └─view 公共视图文件目录
│  │      ├─__public__ 资源文件目录
│  │      └─xxx 模板文件(常用作Layout)
│  │
│  ├─module.go 模块定义文件
│  ├─module 模块目录
│  │  ├─template.go 模板函数
│  │  ├─common.go 公共变量与函数
│  │  ├─controller.go 基础控制器
│  │  ├─controller 控制器目录
│  │  ├─model 模型目录
│  │  └─view 视图文件目录
│  │      └─default 主题文件目录
│  │          ├─__public__ 资源文件目录
│  │          └─xxx 控制器模板目录
│  │
│  └─... 扩展的可装卸功能模块或插件
│
├─deploy 部署文件目录
│
├─conf 配置文件目录
│
└─uploads 上传根目录

安装

1.下载框架源码

go get github.com/henrylee2cn/thinkgo

2.安装部署工具

go install

3.创建项目(在项目目录下运行cmd)

$ thinkgo new appname

4.以热编译模式运行(在项目目录下运行cmd)

$ cd appname
$ thinkgo run

##使用说明

main.go

package main

import (
    "github.com/henrylee2cn/thinkgo/core"

    _ "appname/application"
    _ "appname/application/common"
    _ "appname/deploy"
)

func main() {
    core.ThinkGo.Run()
}

定义模块

package application

import (
    "github.com/henrylee2cn/thinkgo/core"
    // "appname/application/common/middleware"
    _ "appname/application/home"
    . "appname/application/home/controller"
)

func init() {
    // 创建模块,并自动设置default主题
    var m = core.NewModule("这是一个模块示例")

    // 中间件(可选)
    // m.Use(...)

    // 设置主题列表(可选)
    // 若尚未指定当前主题,则默认为第1个
    // m.SetThemes(
    //  &core.Theme{
    //      Name:        "default",
    //      Description: "default",
    //      Src:         map[string]string{},
    //  },
    // )

    // 指定当前主题(可选)
    // m.UseTheme("default")

    // 注册路由
    m.Router(&IndexController{})
}

定义中间件

package middleware

import (
    "fmt"
    "runtime"
    "github.com/henrylee2cn/thinkgo/core"
)

func Recover() core.MiddlewareFunc {
    return func(h core.HandlerFunc) core.HandlerFunc {
        return func(c *core.Context) error {
            defer func() {
                if err := recover(); err != nil {
                    trace := make([]byte, 1<<16)
                    n := runtime.Stack(trace, true)
                    c.Error(fmt.Errorf("panic recover\n %v\n stack trace %d bytes\n %s",
                        err, n, trace[:n]))
                }
            }()
            return h(c)
        }
    }
}

定义控制器

package controller

import (
    "fmt"
    "appname/application/home"
)

type IndexController struct {
    home.BaseController
}

// 后缀"_GET"用于指定GET请求方法
func (this *IndexController) Index_GET() error {
    fmt.Println(this.Query("0"))
    this.Set("content", "Welcome To ThinkGo")
    return this.Render()
}

// 后缀"_ANY"用于指定出websocket外的任何请求方法
func (this *IndexController) Layout_ANY() error {
    fmt.Println(this.Query("a"))
    this.Layout = "/common/layout"
    this.Sections["__CONTENT__"] = this.Path()
    this.Set("content", "Welcome To ThinkGo")
    return this.Render()
}

##FAQ

更多操作可以参考echo的一些用法。

##贡献者名单

贡献者 贡献内容
henrylee2cn 项目发起人
ikfmt cookie功能

##开源协议

ThinkGo 项目采用商业应用友好的 MIT 协议发布。

thinkgo's People

Contributors

andeya avatar miat888 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.