Coder Social home page Coder Social logo

fengxiaomi / thinkgo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andeya/faygo

1.0 1.0 0.0 17.67 MB

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

Go 100.00%

thinkgo's Introduction

#ThinkGo Web Framework GoDoc

ThinkGo Admin

ThinkGo 是一款 Go 语言编写的 web 快速开发框架。它基于开源框架 Gin 进行二次开发,旨在实现一种类 ThinkPHP 的高可用、高效率的 web 框架。在此感谢 Ginhttprouter。它最显著的特点是模块、控制器、操作三段式的标准 MVC 架构,且模块与插件的目录结构完全一致,令开发变得非常简单灵活。

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

ThinkGo Admin

ThinkGo Admin

##目录结构

├─main.go 主文件
│ 
├─core 框架目录
├─application 应用模块目录
│  ├─example.go 模块定义文件
│  ├─example 模块目录
│  │  ├─conf 配置文件目录
│  │  ├─common 公共文件目录
│  │  ├─controller 控制器目录
│  │  ├─model 模型目录
│  │  └─view 视图文件目录
│  │      └─default 主题文件目录
│  │          ├─__public__ 资源文件目录
│  │          └─xxx 控制器模板目录
│  │
│  ├─example2.go 插件定义文件
│  ├─example2 插件目录
│  │  ├─conf 配置文件目录
│  │  ├─common 公共文件目录
│  │  ├─controller 控制器目录
│  │  ├─model 模型目录
│  │  └─view 视图文件目录
│  │      └─default 主题文件目录
│  │          ├─__public__ 资源文件目录
│  │          └─xxx 控制器模板目录
│  │
│  └─... 扩展的可装卸功能模块或插件
│
├─common 公共文件目录
│  ├─deploy 部署文件目录
│  └─utils 工具集
│
├─model 模型目录
├─conf 配置文件目录
└─uploads 上传根目录

安装

go get github.com/henrylee2cn/thinkgo
解压 application.zip 至项目根目录(示例)

##使用说明

main.go

package main

import (
    _ "github.com/henrylee2cn/thinkgo/application"
    "github.com/henrylee2cn/thinkgo/core"
)

func main() {
    core.ThinkGoDefault().
    // 以下为可选设置
    TemplateDelims("{{{","}}}").
    TemplateSuffex(".html").
    TemplateFuncs(map[string]interface{}).
    Use(middleware1,middleware2,middleware3,...).
    // 启动服务
    Run(":8080")
}

定义模块/插件

package application

import (
    "github.com/henrylee2cn/thinkgo/application/admin/conf"
    . "github.com/henrylee2cn/thinkgo/application/admin/controller"
    . "github.com/henrylee2cn/thinkgo/core"
)

func init() {
    ModulePrepare(&Module{
    // 定义插件时改为: AddonPrepare(&Module{
        Name:        conf.NAME,
        Class:       conf.CLASS,
        Description: conf.DESCRIPTION,
    }).SetThemes(
        // 自动设置传入的第1个主题为当前主题
        &Theme{
            Name:        "default",
            Description: "default",
            Src:         map[string]string{},
        },
        &Theme{
            Name:        "blue",
            Description: "blue",
            Src:         map[string]string{
                "img":"/public/banner.jpg",
            },
        },
    ).
        // 指定当前主题
        UseTheme("blue").
        // 中间件
        // Use(...).
        // 注册路由,且可添加中间件
        GET("/index?addon", &IndexController{}).
        HEAD("/to", &IndexController{}).
        DELETE("/del/:addon", someHandlerFunc, &IndexController{}).
        POST("/add", &IndexController{}, someHandlerFunc).
        PUT("/ReadMail", someHandlerFunc, &ReadController{}, someHandlerFunc).
        PATCH("/ReadMail", someHandlerFunc, &ReadController{}, someHandlerFunc).
        OPTIONS("/ReadMail", someHandlerFunc, &ReadController{}, someHandlerFunc)
}

定义控制器

package controller

import (
    "github.com/henrylee2cn/thinkgo/application/admin/common"
)

type IndexController struct {
    common.BaseController
}

func (this *IndexController) Index() {
    // 当url类似 "/admin/index/index?addon=mail" 时,这样获取参数
    id := this.Query("addon")
    if id == "" {
    // 当url类似 "/admin/index/index/mail" 时,这样获取参数
        id = this.Param("addon")
    }
    // 传入模板变量
    this.Data["name"] = "henrylee2cn"
    // 渲染模板并写回响应流
    this.HTML()
}

##开源协议

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

thinkgo's People

Contributors

andeya avatar

Stargazers

 avatar

Watchers

 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.