gei

package module
v0.0.0-...-5931f28 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: MIT Imports: 13 Imported by: 0

README

须知

本项目是模仿 golang的web开源框架Gin,主要复现了 前缀路由 分组控制 中间件 等逻辑代码。 其中对/login,/logout,/signin,/info 等接口进行了定义和实现

如何安装

安装 Go:从 官方网站 下载并安装 Go,

创建项目文件夹结构:在工作目录下,创建一个项目文件夹,比如 myproject,然后将你的代码文件夹 gei 移动到 myproject 下。

安装依赖项:在项目的根目录下,打开终端或命令提示符,运行以下命令来安装项目的依赖项

Copy code
go get -u github.com/go-sql-driver/mysql
go get -u gopkg.in/gomail.v2

这将会自动下载并安装这些依赖项到你的 Go 工作区。

编译项目:在终端中切换到 myproject 目录下,运行以下命令编译你的项目:

Copy code
go build gei

这将会生成一个可执行文件(如果你的代码包含 main 函数)。 运行项目:运行生成的可执行文件来启动你的项目:

Copy code
./gei

或者,如果你使用 Windows:

Copy code
gei.exe

快速开始

package main

import (
	"gei"
	"net/http"
)

const (
	cookiename = "user-cookie"
	secretKey  = "your-secret-key"
)

func main() {
	r := gei.New()
	r.RunMiddware(gei.Logger())
	r.GET("/", func(c *gei.Context) {
		c.HTML(http.StatusOK, "<h1>Hello Gee</h1>")
	})
	r.Run(":9999")
}

能快速验证/login,/logout,/signin,/info 几个功能、

配置说明

邮箱配置
m.SetHeader("From", "邮件地址1")
m.SetHeader("To", "邮件地址2")
d := gomail.NewDialer("smtp.邮件地址1的邮箱类型(qq/163).com", 587, "邮件地址1", "邮件地址1密钥)
数据库配置

安装好数据库驱动后 ,就进行对数据库的设置

			db, err := sql.Open("mysql", "用户名:数据库密码@tcp(主机名:端口号)/数据库名")
			if err != nil {
				fmt.Println("Failed to connect to the database:", err)
				return
			}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Writer     http.ResponseWriter
	Req        *http.Request
	Path       string
	Method     string
	Params     map[string]string
	StatusCode int
	// contains filtered or unexported fields
}

func (*Context) Data

func (c *Context) Data(code int, data []byte)

func (*Context) HTML

func (c *Context) HTML(code int, html string)

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

func (*Context) Next

func (c *Context) Next()

func (*Context) Param

func (c *Context) Param(key string) string

func (*Context) PostForm

func (c *Context) PostForm(key string) string

func (*Context) Query

func (c *Context) Query(key string) string

func (*Context) ServeHTMLFile

func (c *Context) ServeHTMLFile(filename string)

func (*Context) SetHeader

func (c *Context) SetHeader(key string, value string)

func (*Context) Status

func (c *Context) Status(code int)

func (*Context) String

func (c *Context) String(code int, format string, values ...interface{})

type Engine

type Engine struct {
	*RouterGroup
	// contains filtered or unexported fields
}

func New

func New() *Engine

func (*Engine) GET

func (engine *Engine) GET(pattern string, handler HandlerFunc)

func (*Engine) POST

func (engine *Engine) POST(pattern string, handler HandlerFunc)

func (*Engine) Run

func (engine *Engine) Run(addr string) (err error)

func (*Engine) ServeHTTP

func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)

type H

type H map[string]interface{}

type HandlerFunc

type HandlerFunc func(*Context)

func AuthenticateMiddleware

func AuthenticateMiddleware() HandlerFunc

func Logger

func Logger() HandlerFunc

func Login

func Login() HandlerFunc

func Signup

func Signup() HandlerFunc

type L

type L map[string]interface{}

type R

type R map[string]interface{}

type RouterGroup

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

func (*RouterGroup) GET

func (routergroup *RouterGroup) GET(pattern string, handler HandlerFunc)

func (*RouterGroup) NewRouterGroup

func (routergroup *RouterGroup) NewRouterGroup(prefix string) *RouterGroup

func (*RouterGroup) POST

func (routergroup *RouterGroup) POST(pattern string, handler HandlerFunc)

func (*RouterGroup) RunMiddware

func (routergroup *RouterGroup) RunMiddware(midware ...HandlerFunc)

Jump to

Keyboard shortcuts

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