letgo is an open-source, high-performance web framework for the Go programming language.

letgo Web Framework

letgo is an open-source, high-performance web framework for the Go programming language.

my email :[email protected]

oschina: https://gitee.com/WJPone

Contents

Installation

To install letgo package, you need to install Go and set your Go workspace first.

  1. The first need Go installed (version 1.12+ is required), then you can use the below Go command to install letgo.
$ go get -u github.com/wjpxxx/letgo
  1. Import it in your code:
import "github.com/wjpxxx/letgo"

Quick start

Web

package main

import (
    "github.com/wjpxxx/letgo/web"
    "github.com/wjpxxx/letgo/web/context"
	"github.com/wjpxxx/letgo/web/filter"
	"fmt"
)

func main() {
	web.AddFilter("/user/*",filter.BEFORE_ROUTER,func(ctx *context.Context){
		ctx.Output.JSON(200,lib.InRow{
			"www":"fff",
		})
	})
	web.LoadHTMLGlob("templates/*")
	web.Get("/", func(ctx *context.Context){
		//ctx.Output.Redirect(301,"http://www.baidu.com")
		x:=ctx.Input.Param("a")
		if x!=nil{
			ctx.Session.Set("a",x.Int())
			var a int
			ctx.Session.Get("a",&a)
			fmt.Println("a:",a,"x:",x.Int())
		}
		ctx.Output.HTML(200,"index.tmpl",lib.InRow{
			"title":"wjp",
		})
	})
	
	web.Post("/user/:id([0-9]+)", func(ctx *context.Context){
		type A struct{
			Data string `json:"data"`
			ShopID int64 `json:"shop_id"`
		}
		a:=A{}
		ctx.SetCookie("a", "234234")
		ctx.Input.BindJSON(&a)
		fmt.Println(a)
		ctx.Output.YAML(500,lib.InRow{
			"message":"123123",
			"b":2,
		})
	})

	web.Get("/user/:id([0-9]+)/:id3([0-9]+)", func(ctx *context.Context){
		ctx.Output.XML(200,lib.InRow{
			"message":"123123",
			"b":2,
		})
	})

	web.Run()//listen and serve on 0.0.0.0:1122 (for windows "localhost:1122")
}

Serving static files

func main() {
	web.Static("/assets/", "./assets")
	web.StaticFile("/1.png", "./assets/b3.jpg")
	web.Run()
}

Register controller

type UserController struct{}
func (c *UserController)Add(ctx *context.Context){
	ctx.Output.Redirect(302,"/")
}
func main() {
	c:=&UserController{}
	web.RegisterController(c)
	c2:=&UserController{}
	web.RegisterController(c2,"get:add")
	web.Run()
}

Captcha

package main

import (
	"github.com/wjpxxx/letgo/web/captcha"
	"image/color"
	"github.com/wjpxxx/letgo/file"
	"fmt"
)

func main(){
	c:=captcha.NewCaptcha()
	c.AddFonts("STHUPO.TTF")
	c.AddColors(color.RGBA{255,0,255,255},color.RGBA{0,255,255,255},color.Black)
	c.SetSize(200,60)
	//c.AddBackColors(color.Black,color.Opaque)
	//c.Create(4,NUM)
	//c.Create(4,LCHAR)
	//c.SetDisturbLevel(HIGH)
	c.SetDisturbLevel(captcha.MEDIUM)
	img1,code1:=c.Create(4,captcha.ALL)
	//img1.DrawLine(10,0,100,20,color.RGBA{255,0,255,255})
	img1.SaveImage("1.png")
	img2,code2:=c.Create(4,captcha.ALL)
	file.PutContent("2",img2.Base64Encode())
	img2.SaveImage("2.png")
	fmt.Println(code1,code2)
}

Model operation

package main

import "github.com/wjpxxx/letgo/db/mysql"
func main() {
    model:=NewModel("dbname","tablename")
    m:=model.Fields("*").
            Alias("m").
            Join("sys_shopee_shop as s").
            On("m.id","s.master_id").
            OrOn("s.master_id",1).
            AndOnRaw("m.id=1 or m.id=2").
            LeftJoin("sys_lazada_shop as l").
            On("m.id", "l.master_id").
            WhereRaw("m.id=1").
            AndWhere("m.id",2).
            OrWhereIn("m.id",lib.Int64ArrayToInterfaceArray(ids)).
            GroupBy("m.id").
            Having("m.id",1).
            AndHaving("m.id",1).
            OrderBy("m.id desc").Find()
    fmt.Println(model.GetLastSql())
    fmt.Println(m["master_id"].Int64(),m["name"],m["age"].Int(),m["password"].String())
}

RPC

import "github.com/wjpxxx/letgo/net/rpc"

func main(){
	s:=rpc.NewServer()
	//s.RegisterName("Hello",new(Hello))
	s.Register(new(Hello))
	go func(){
		for{
			time.Sleep(10*time.Second)
			var reply string
			//rpc.NewClient().WithAddress("127.0.0.1","8080").Call("Hello.Say","nihao",&reply).Close()
			rpc.NewClient().Start().Call("Hello.Say","nihao",&reply).Close()
			fmt.Println(reply)
			rm:=rpc.RpcMessage{
				Method: "Hello.Say",
				Args: "rpc message",
				Callback: func(a interface{}){
					fmt.Println(a.(string))
				},
			}
			rpc.NewClient().Start().CallByMessage(rm).Close()
		}
	}()
	s.Run()
}

Command

import "github.com/wjpxxx/letgo/command/command"

func main(){
	cmd:=command.New().Cd("D:\\Development\\go\\web\\src").SetCMD("dir")
	//cmd.AddPipe(New().SetCMD("find","'\\c'","'80'"))
	cmd.Run()
}

Synchronize files

1.server config in config/sync_server.config

{"ip":"127.0.0.1","port":"5566"}

start server

./main server

2.client config in config/sync_client.config

{
    "locationPath":"D:/Development/go/web/src/sync-v2", //Local directory to be synchronized
    "remotePath":"/root/new/buyer2",	//Directory stored on the server
    "filter":[			//Filter out files that are not synchronized to the server
        "main.go",
        "runtime/cache/sync/*"
    ],
    "server":{
        "ip":"127.0.0.1",	//Server IP
        "port":"5566",
        "slave":[
            {
                "ip":"127.0.0.2",	//For other servers, it is recommended to be in the same LAN as the server
                "port":"5566"
            }
        ]
    }
}

start file

./main file

The client sends the file to be synchronized to the server, and then the server synchronizes the file to the slave

3.start cmd

./main cmd

The client sends the console command to the server, and at the same time, it also sends it to the slave, and the concurrent execution interface returns

4.go code

1{ if args[1]=="server"{ plugin.Plugin("sync-server").Run() } else if args[1]=="file"{ plugin.Plugin("sync-file").Run() } else if args[1]=="cmd"{ rs:=plugin.Plugin("sync-cmd").Run("/www/","ls -al") result:=rs.(map[string]syncconfig.CmdResult) fmt.Println(result) } } ">
package main

import (
	"github.com/wjpxxx/letgo/plugin"
	"github.com/wjpxxx/letgo/plugin/sync/syncconfig"
	"fmt"
	"os"
)


func main() {
	args:=os.Args
	if len(args)>1{
		if args[1]=="server"{
			plugin.Plugin("sync-server").Run()
		} else if args[1]=="file"{
			plugin.Plugin("sync-file").Run()
		} else if args[1]=="cmd"{
			rs:=plugin.Plugin("sync-cmd").Run("/www/","ls -al")
			result:=rs.(map[string]syncconfig.CmdResult)
			fmt.Println(result)
		}
	}

Task

Creating memory resident applications When the stop method is called, all tasks will wait for execution and exit

package main

import (
	"github.com/wjpxxx/letgo/cron/task"
	"time"
	"fmt"
)

func main() {
	task.RegisterTask("add",1,func(ctx *Context){
		fmt.Println(ctx.Name,ctx.TaskNo)
		//fmt.Println()
		//time.Sleep(1*time.Second)
	})
	go func(){
		time.Sleep(15*time.Second)
		task.Stop()
	}()
	//task.Start()
	task.StartAndWait()
}

Crontab

Creating Crontab

package main
import (
	"github.com/wjpxxx/letgo/cron/context"
	"github.com/wjpxxx/letgo/lib"
	"fmt"
	"time"
)
func main() {
	AddCron("cron1","*/6 * * * * *",func(ctx *context.Context){
		fmt.Println("cron1", lib.Now())
	})
	AddCron("cron2","*/3 * * * * *",func(ctx *context.Context){
		fmt.Println("cron2", lib.Now())
	})
	go func(){
		time.Sleep(10*time.Second)
		Stop()
	}()
	StartAndWait()
}
Owner
wjp
Web/go golang letgo developer - Crypto-wujianping. Golang 💕 OpenSource! fujian.quanzhou
wjp
Similar Resources

Goal is a toolkit for high productivity web development in Go language in the spirit of Revel Framework that is built around the concept of code generation.

Goal Goal is a set of tools for high productivity web development in Go language. Goal, being mostly inspired by Revel Framework and its discussions,

Sep 27, 2021

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang.

GoFrame English | 简体中文 GoFrame is a modular, powerful, high-performance and enterprise-class application development framework of Golang. If you're a

Jan 2, 2023

Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Jan 5, 2023

Golanger Web Framework is a lightweight framework for writing web applications in Go.

/* Copyright 2013 Golanger.com. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

Nov 14, 2022

The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework.

jin About The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework. If thi

Jul 14, 2022

Go-app is a package to build progressive web apps with Go programming language and WebAssembly.

Go-app is a package to build progressive web apps with Go programming language and WebAssembly.

Go-app is a package to build progressive web apps with Go programming language and WebAssembly.

Dec 30, 2022

Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance. Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo is an HTTP web framework written in Go (Golang).It features a Tornado-like API with better performance.  Tigo是一款用Go语言开发的web应用框架,API特性类似于Tornado并且拥有比Tornado更好的性能。

Tigo(For English Documentation Click Here) 一个使用Go语言开发的web框架。 相关工具及插件 tiger tiger是一个专门为Tigo框架量身定做的脚手架工具,可以使用tiger新建Tigo项目或者执行其他操作。

Jan 5, 2023

Package macaron is a high productive and modular web framework in Go.

Package macaron is a high productive and modular web framework in Go.

Macaron Package macaron is a high productive and modular web framework in Go. Getting Started The minimum requirement of Go is 1.6. To install Macaron

Jan 2, 2023

A high level web-framework for Go

go-start is a high level web-framework for Go, like Django for Python or Rails for Ruby. Installation: go get github.com/ungerik/go-start Documentatio

Dec 24, 2022
beego is an open-source, high-performance web framework for the Go programming language.
beego is an open-source, high-performance web framework for the Go programming language.

Beego Beego is used for rapid development of enterprise application in Go, including RESTful APIs, web apps and backend services. It is inspired by To

Jan 8, 2023
High performance, minimalist Go web framework
High performance, minimalist Go web framework

Supported Go versions As of version 4.0.0, Echo is available as a Go module. Therefore a Go version capable of understanding /vN suffixed imports is r

Jan 2, 2023
Gearbox :gear: is a web framework written in Go with a focus on high performance
Gearbox :gear: is a web framework written in Go with a focus on high performance

gearbox ⚙️ is a web framework for building micro services written in Go with a focus on high performance. It's built on fasthttp which is up to 10x fa

Jan 3, 2023
hiboot is a high performance web and cli application framework with dependency injection support

Hiboot - web/cli application framework About Hiboot is a cloud native web and cli application framework written in Go. Hiboot is not trying to reinven

Nov 20, 2022
Gearbox :gear: is a web framework written in Go with a focus on high performance
Gearbox :gear: is a web framework written in Go with a focus on high performance

gearbox ⚙️ is a web framework for building micro services written in Go with a focus on high performance. It's built on fasthttp which is up to 10x fa

Dec 29, 2022
High performance, simple Go web framework

Elton Elton的实现参考了koa以及echo,中间件的调整均为洋葱模型:请求由外至内,响应由内至外。主要特性如下: 处理函数(中间件)均以返回error的形式响应出错,方便使用统一的出错处理中间件将出错统一转换为对应的输出(JSON),并根据出错的类型等生成各类统计分析 成功响应数据直接赋值

Dec 17, 2022
Dragon 🐲 🐲 🐲 is an enterprise high performance web framework with Go for the feature and comfortable develop.

Dragon start dragon ab performance Dragon ?? ?? ?? is a lightweight high performance web framework with Go for the feature and comfortable develop. 中文

Sep 14, 2022
Dragon 🐲 🐲 🐲 is a lightweight high performance web framework with Go for the feature and comfortable develop.

Dragon project new link start dragon ab performance Dragon ?? ?? ?? is a lightweight high performance web framework with Go for the feature and comfor

Sep 6, 2022
A high productivity, full-stack web framework for the Go language.

Revel Framework A high productivity, full-stack web framework for the Go language. Current Version: 1.0.0 (2020-07-11) Supports go.mod package managem

Jan 7, 2023