golang http server wrapper

Related tags

yong
Overview

Yong Simple Web Framework

This project benchmarked gin-gonic.

License: MIT issue badge forks badge stars badge

Installation

  1. Go command to install Yong.
    $ go get -u github.com/rladyd818/yong
  2. Import it in your code
    import "github.com/rladyd818/yong"

Simple example

package main
import (
    "github.com/rladyd818/yong"
    "fmt"
)
func main() {
    r := yong.Default()
    r.GET("/", func(c *yong.Context) {
        fmt.Fprint(c.Writer, "Hello World")
    })
    r.Run(":8000")
}

Method type list

GET, POST, PUT, PATCH, DELETE, OPTIONS

Using Middleware example

package main
import (
    "github.com/rladyd818/yong"
    "fmt"
)

func middleware() yong.HandlerFunc {
    return func(c *yong.Context) {
        c.Writer.Header().Set("m1", "Execute middleware")
    }
}

func middleware2() yong.HandlerFunc {
    return func(c *yong.Context) {
        c.Writer.Header().Set("m2", "Execute middleware2")
    }
}

func main() {
    r := yong.Default()
    r.USE("/", middleware(), middleware2()) // The "USE" method defines middleware.
    r.GET("/", func(c *yong.Context) {
        m1 := c.Writer.Header().Get("m1")
        m2 := c.Writer.Header().Get("m2")
        fmt.Println(m1)
	fmt.Println(m2)
        
        fmt.Fprint(c.Writer, "middleware Test") // response "middleware Test"
    })
    r.Run(":8000")
}

Result:

Execute middleware
Execute middleware2

CORS Policy processing using middleware example

func CORSMiddleware() yong.HandlerFunc {
	return func(c *yong.Context) {
		c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Origin, Accept")
		c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
		c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000") // Your client origin
		c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, DELETE, POST, OPTIONS")
		if c.Request.Method == "OPTIONS" {
			c.Writer.WriteHeader(204)
		}
	}
}

func main() {
    r := yong.Default()
    r.USE("/users", CORSMiddleware()) // The "USE" method defines middleware.
    r.GET("/users", func(c *yong.Context) {
        fmt.Fprint(c.Writer, "CORS Policy processing") // response "CORS Policy processing"
    })
    r.Run(":8000")
}
Issues
Releases(v1.0)
A toy MMO example built using Ebiten and WebRTC DataChannels (UDP)

Ebiten WebRTC Toy MMO ⚠️ This is a piece of incomplete hobby work and not robust. Please read the "Why does this project exist?" section. What is this

Jae Bentvelzen 8 Jun 3, 2021
Hprose 1.0 for Golang (Deprecated). Hprose 2.0 for Golang is here:

Hprose for Golang Introduction Installation Usage Http Server Http Client Synchronous Invoking Synchronous Exception Handling Asynchronous Invoking As

Hprose 137 Feb 20, 2021
A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.

frp README | 中文文档 What is frp? frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it s

null 46k Jun 12, 2021
Chisel is a fast TCP/UDP tunnel, transported over HTTP, secured via SSH.

Chisel is a fast TCP/UDP tunnel, transported over HTTP, secured via SSH. Single executable including both client and server. Written in Go (golang). Chisel is mainly useful for passing through firewalls, though it can also be used to provide a secure endpoint into your network.

Jaime Pillora 6k Jun 12, 2021
Access more HTTP ports over CDN with this application.

More-Ports More Ports is a proxy service to establish all web-based applications on different ports on the server-side over a well known TCP port. It

Ahmet ÖZER 3 May 16, 2021
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.

gev 中文 | English gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily bui

徐旭 1.2k Jun 13, 2021
In memory Key/Value store in go using gRPC.

In memory cache, using gRPC Contents About Running Server Local Docker Kubernetes Example Helm Terraform API Add Get GetByPrefix GetAllItems DeleteKey

Kautilya Tripathi 136 May 20, 2021
webrpc is a schema-driven approach to writing backend services for modern Web apps and networks

webrpc is a schema-driven approach to writing backend servers for the Web. Write your server's api interface in a schema format of RIDL or JSON, and t

null 368 May 29, 2021
CoAP Client/Server implementing RFC 7252 for the Go Language

Canopus Canopus is a client/server implementation of the Constrained Application Protocol (CoAP) Updates 25.11.2016 I've added basic dTLS Support base

Zubair Hamed 144 Apr 11, 2021
Glue - Robust Go and Javascript Socket Library (Alternative to Socket.io)

Glue - Robust Go and Javascript Socket Library Glue is a real-time bidirectional socket library. It is a clean, robust and efficient alternative to so

DesertBit 377 Jun 3, 2021
Go HTTP tunnel is a reverse tunnel based on HTTP/2.

Go HTTP tunnel is a reverse tunnel based on HTTP/2. It enables you to share your localhost when you don't have a public IP.

Michal Jan Matczuk 2.7k Jun 11, 2021
Use Consul to do service discovery, use gRPC +kafka to do message produce and consume. Use redis to store result.

目录 gRPC/consul/kafka简介 gRPC+kafka的Demo gRPC+kafka整体示意图 限流器 基于redis计数器生成唯一ID kafka生产消费 kafka生产消费示意图 本文kafka生产消费过程 基于pprof的性能分析Demo 使用pprof统计CPU/HEAP数据的

null 38 Jan 31, 2021
A protoc-gen-go wrapper including an RPC stub generator

// Copyright 2013 Google. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE fi

Kyle Lemons 35 May 13, 2020
Multiplexer over TCP. Useful if target server only allows you to create limited tcp connections concurrently.

tcp-multiplexer Use it in front of target server and let your client programs connect it, if target server only allows you to create limited tcp conne

许嘉华 3 May 27, 2021