Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/rumPublic

Package rum implements an HTTP server. The rum server is compatible with net/http and faster than net/http.

License

NotificationsYou must be signed in to change notification settings

hslam/rum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PkgGoDevBuild StatuscodecovGo Report CardLICENSE

Package rum implements an HTTP server. The rum server is compatible with net/http and faster than net/http.

Features

qpsp99

Get started

Install

go get github.com/hslam/rum

Import

import "github.com/hslam/rum"

Usage

Simple Example

package mainimport ("github.com/hslam/rum""net/http")funcmain() {m:=rum.New()m.HandleFunc("/",func(w http.ResponseWriter,r*http.Request) {w.Write([]byte("Hello World"))})m.Run(":8080")}

curlhttp://localhost:8080

Hello World

Example

package mainimport ("github.com/hslam/rum""net/http")funcmain() {m:=rum.New()m.SetPoll(true)m.Recovery(rum.Recovery)m.NotFound(func(w http.ResponseWriter,r*http.Request) {http.Error(w,"Not Found : "+r.URL.String(),http.StatusNotFound)})m.Use(func(w http.ResponseWriter,r*http.Request) {w.Header().Set("Access-Control-Allow-Origin","*")})m.HandleFunc("/",func(w http.ResponseWriter,r*http.Request) {w.Write([]byte("Hello World"))})m.HandleFunc("/hello/:name",func(w http.ResponseWriter,r*http.Request) {params:=m.Params(r)w.Write([]byte("Hello "+params["name"]))}).GET()m.Group("/group",func(m*rum.Mux) {m.HandleFunc("/foo/:id",func(w http.ResponseWriter,r*http.Request) {params:=m.Params(r)w.Write([]byte("group/foo id:"+params["id"]))}).GET()m.HandleFunc("/bar/:id",func(w http.ResponseWriter,r*http.Request) {params:=m.Params(r)w.Write([]byte("group/bar id:"+params["id"]))}).GET()})m.Run(":8080")}

curlhttp://localhost:8080/hello/rum

Hello rum

curlhttp://localhost:8080/group/foo/1

group/foo id:1

curlhttp://localhost:8080/group/bar/2

group/bar id:2

Use Other Router Example

The router must implement the http.Handler interface, for example using the http.ServeMux.

package mainimport ("github.com/hslam/rum""net/http")funcmain() {router:=http.NewServeMux()router.HandleFunc("/",func(w http.ResponseWriter,r*http.Request) {w.Write([]byte("Hello World"))})server:=rum.New()server.Handler=routerserver.Run(":8080")}

License

This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)

Author

rum was written by Meng Huang.

About

Package rum implements an HTTP server. The rum server is compatible with net/http and faster than net/http.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp