• Stars
    star
    283
  • Rank 146,066 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight, idiomatic and stable for building Go 1.7+ HTTP services

Doggy

Build Status Go Report Card

Lightweight, idiomatic and stable for building Go 1.7+ HTTP services. It aims to provide a composable way to develop HTTP services.

dependency

Generate api struct

curl -s https://api.github.com/repos/chimeracoder/gojson | gojson -name=Repository -tags=schema,json

Generate model package

xo mysql://user:passwd@host:port/db -o . --template-path templates --ignore-fields updateTime

Example

package main

import (
	"net/http"
	"net/url"
	"time"

	"github.com/hnlq715/doggy"
	"github.com/hnlq715/doggy/httpclient"
	"github.com/hnlq715/doggy/middleware"
	"github.com/hnlq715/doggy/render"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {

	m := doggy.NewMux()

	m.Handle("/metrics", promhttp.Handler())
	m.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		processTime := 4 * time.Second
		ctx := r.Context()
		select {
		case <-ctx.Done():
			return
		case <-time.After(processTime):
		}
		render.Text(w, 200, "pong")
	})

	m.HandleFunc("/get", func(w http.ResponseWriter, r *http.Request) {
		data := make(map[string]interface{})
		u, _ := url.Parse("http://httpbin.org/get")
		u.RawQuery = r.Form.Encode()
		err := httpclient.Get(r.Context(), u.String()).ToJSON(&data)
		if err != nil {
			render.Text(w, 200, err.Error())
			return
		}
		render.JSON(w, 200, data)
	})

	n := doggy.Classic()
	n.Use(middleware.NewPrometheus())
	n.UseHandler(m)

	doggy.ListenAndServeGracefully(n)
}

More Repositories

1

nginx-vts-exporter

Simple server that scrapes Nginx vts stats and exports them via HTTP for Prometheus consumption
Go
638
star
2

httpmq

A simple HTTP message queue written in Go with goleveldb, just like httpsqs written in C with Tokyo Cabinet.
Go
308
star
3

gofluent

(Not Maintained) Something acting like fluentd rewritten in Go.
Go
180
star
4

nginx-prometheus-metrics

A production demo to collect prometheus metrics for nginx with lua embedded.
Lua
95
star
5

gobreak

Latency and fault tolerance library like Netflix's Hystrix with prometheus and gobreaker.
Go
44
star
6

go-loadbalance

A well designed loadbalance API with dozens of implementations for go-grpc loadbalance.
Go
38
star
7

goroutine-pool

A simple goroutine pool which can create and release goroutine dynamically, inspired by fasthttp.
Go
32
star
8

nginx_upstream_check_module

(Not maintained) This module can be used in pure nginx-1.4.7 and nginx-1.6.2 to check upstream servers, with several patches applied.
C
17
star
9

status-nginx-module

A http status module for pure nginx, which is in production already.
C
14
star
10

graphql-grpc-gateway

Go
10
star
11

zrpc

A lightweight distributed RPC framework powered by pure C language and based on ZeroMQ and pbc.
C
9
star
12

struct2interface

Development helper program that generates a Golang interface by inspecting the structure methods of an existing .go file.
Go
7
star
13

rsa

RAS crypto algorithm for Decrypt with Public Key and Encrypt with Private Key.
Go
6
star
14

httpmq-rs

A simple HTTP message queue written in Rust with rocksdb, just like httpmq written in Go with leveldb.
Rust
3
star
15

lua-resty-fluent

A simple fluent client based on openresty.
Lua
3
star
16

practice-to-intergrate-k8s

A practice to integrate golang, microservice and so on... with k8s
Go
2
star
17

data_struct

Common data structures
C
1
star
18

srt2fcpxml

Go
1
star
19

architecture-best-practice

Best practice from the ground up.
1
star
20

github-trending

A toy to play with weixin mp and github.
Go
1
star
21

proto

Simplify developing HTTP API through Protobuf way.
Go
1
star
22

High-Performance-Browser-Networking-cn

中文翻译
1
star
23

awesome-nginx

A collection of awsome resources around nginx.
1
star
24

ratelimitx

A simple ratelimit for golang, implemented with memcache and gobreak, aims on high availability.
Go
1
star
25

enhanced-limit-conn-nginx-module

An enhanced limit conn nginx module.
C
1
star
26

jumpcutter

An auto jump cutter, implemented with opencv and silence detect.
Python
1
star