All Projects → AmyangXYZ → sgo

AmyangXYZ / sgo

Licence: MIT license
A simple, light and fast Web framework written in Go.

Programming Languages

go
31211 projects - #10 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to sgo

Vox
Simple and lightweight Go web framework inspired by koa
Stars: ✭ 74 (-1.33%)
Mutual labels:  lightweight, webframework
XYFSnowAnimation
A category of NSTimer for showing 3D Fluttered animation for iOS, which is used very simply. Lightweight CALayer animation, core animation, 3D transform, performance safety. iOS 3D三维飘落下雪落花动画,轻量级CALayer图层动画,核心动画,3D形变,性能安全,定时器NSTimer分类,直接使用,很简单
Stars: ✭ 15 (-80%)
Mutual labels:  lightweight
copy-translator
简单、轻量、好用的划词翻译软件
Stars: ✭ 979 (+1205.33%)
Mutual labels:  lightweight
i18n-core
i18n-core is a no-fuzz Node.js implementation of i18n.
Stars: ✭ 14 (-81.33%)
Mutual labels:  lightweight
cli
a lightweight and simple cli package
Stars: ✭ 12 (-84%)
Mutual labels:  lightweight
tb-grid
tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.
Stars: ✭ 19 (-74.67%)
Mutual labels:  lightweight
xdecor
A decoration mod for Minetest meant to be light, simple and well-featured
Stars: ✭ 25 (-66.67%)
Mutual labels:  lightweight
Teapot
Teapot micro web framework for Pharo Smalltalk
Stars: ✭ 86 (+14.67%)
Mutual labels:  webframework
plexydesk
Lightweight Desktop Manager for Gnu/Linux and FreeBSD - Ideal for Low resource computers
Stars: ✭ 33 (-56%)
Mutual labels:  lightweight
brute-md5
Advanced, Light Weight & Extremely Fast MD5 Cracker/Decoder/Decryptor written in Python 3
Stars: ✭ 16 (-78.67%)
Mutual labels:  lightweight
vim-config
My .vimrc config
Stars: ✭ 20 (-73.33%)
Mutual labels:  lightweight
firmeve
a out-of-the-box, full-featured go framework supporting http, http2, websocket, tcp, udp, rpc and microservice
Stars: ✭ 36 (-52%)
Mutual labels:  webframework
go-baseapp
A lightweight starting point for Go web servers
Stars: ✭ 61 (-18.67%)
Mutual labels:  lightweight
lexer
Hackable Lexer with UTF-8 support
Stars: ✭ 19 (-74.67%)
Mutual labels:  lightweight
Rakkit
🌐 A framework written in TypeScript that provides REST/GraphQL API and Websocket tools to build amazing server-side applications
Stars: ✭ 32 (-57.33%)
Mutual labels:  lightweight
khudro
Khudro is a very light weight web-server built with C.
Stars: ✭ 19 (-74.67%)
Mutual labels:  lightweight
canorus
Canorus is a free cross-platform music score editor
Stars: ✭ 25 (-66.67%)
Mutual labels:  lightweight
sitefox
Node + cljs backend web framework
Stars: ✭ 180 (+140%)
Mutual labels:  webframework
query2report
Query2Report is a simple open source business intelligence platform that allows users to build report/dashboard for business analytics or enterprise reporting
Stars: ✭ 43 (-42.67%)
Mutual labels:  lightweight
flask-empty-api
AZAP Flask boilerplate for creating API's with flask.
Stars: ✭ 15 (-80%)
Mutual labels:  webframework

SGo

SGo is a simple, light and fast Web framework written in Go.

The source is easy to learn, then you can make your own Go Web Framework!

Features

  • Pretty and fast router - based on radix tree
  • Middleware Support
  • Friendly to REST API
  • No regexp or reflect
  • QUIC Support
  • Inspired by many excellent Go Web framework

Installation

go get github.com/AmyangXYZ/sgo

Example

Simple

package main

import (
    "github.com/AmyangXYZ/sgo"
)

func main() {
    app := sgo.New()
    app.GET("/", func(ctx *sgo.Context) error {
        return ctx.Text(200, "Hello")
    })
    app.Run(":16311")
}

Further

For vue2 projects, add module.exports = {assetsDir: 'static', css: { extract: false }} to vue.config.js, then npm run build && tar caf dist.tar.xz dist and copy dist.tar.xz and run ./deployFrontend.sh.

package main

import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/AmyangXYZ/sgo"
	"github.com/gorilla/websocket"
)

const (
	addr = ":8888"
)

var upgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
}

func main() {
	app := sgo.New()
	app.SetTemplates("./templates", nil)
	app.GET("/", index)
	app.GET("/static/*files", static)

	app.GET("/api/boottime", getBootTime)
	app.GET("/ws/comm", wsComm)
	app.POST("/api/link/:name", postHandler)
	app.OPTIONS("/api/link/:name", sgo.PreflightHandler)

	if err := app.Run(addr); err != nil {
		log.Fatal("Listen error", err)
	}
}

// Index page handler.
func index(ctx *sgo.Context) error {
	return ctx.Render(200, "index")
}

// Static files handler.
func static(ctx *sgo.Context) error {
	staticHandle := http.StripPrefix("/static",
		http.FileServer(http.Dir("./static")))
	staticHandle.ServeHTTP(ctx.Resp, ctx.Req)
	return nil
}

func getBootTime(ctx *sgo.Context) error {
	return ctx.Text(200, fmt.Sprintf("%d", 20))
}

func wsComm(ctx *sgo.Context) error {
	ws, err := upgrader.Upgrade(ctx.Resp, ctx.Req, nil)
	breakSig := make(chan bool)
	if err != nil {
		return err
	}
	fmt.Println("ws/comm connected")
	defer func() {
		ws.Close()
		fmt.Println("ws/comm client closed")
	}()
	go func() {
		for {
			_, _, err := ws.ReadMessage()
			if err != nil {
				breakSig <- true
			}
		}
	}()
	for {
		select {
		// case l := <-LogsComm:
		// 	ws.WriteJSON(l)
		case <-breakSig:
			return errors.New("stop ws")
		}
	}
}

func postHandler(ctx *sgo.Context) error {
	// param request
	fmt.Println(ctx.Params)
	// json body request
	body, err := ioutil.ReadAll(ctx.Req.Body)
	if err != nil {
		return err
	}
	fmt.Println(string(body))
	var data map[string]interface{}
	json.Unmarshal(body, &data)

	return ctx.Text(200, "xx")
}

example

My Blog is also powered by SGo.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].