
간단하고 쉬운 웹 마이크로 프레임 워크
중요 : 이제 GO1.9+ 버전 지원이 필요하며 Go Mod를 지원하십시오.
문서 : https://www.kancloud.cn/devfeel/dotweb/346608
가이드 : https://github.com/devfeel/dotweb/blob/master/docs/guide.md
go get github.com/devfeel/dotweb
package main
import (
"fmt"
"github.com/devfeel/dotweb"
)
func main () {
//init DotApp
app := dotweb . New ()
//set log path
app . SetLogPath ( "/home/logs/wwwroot/" )
//set route
app . HttpServer . GET ( "/index" , func ( ctx dotweb. Context ) error {
return ctx . WriteString ( "welcome to my first web!" )
})
//begin server
fmt . Println ( "dotweb.StartServer begin" )
err := app . StartServer ( 80 )
fmt . Println ( "dotweb.StartServer error => " , err )
}| 도트 월 | 1.9.2 | 16core16g | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CPU | 메모리 | 샘플 | 평균 | 중앙값 | 90%라인 | 95%라인 | 99%라인 | 최소 | 맥스 | 오류% | 처리량 | KB/SEC를 받았습니다 | KB/SEC를 보내십시오 |
| 40% | 39m | 15228356 | 19 | 4 | 43 | 72 | 204 | 0 | 2070 | 0.00% | 48703.47 | 7514.79 | 8656.28 |
| 40% | 42m | 15485189 | 18 | 4 | 41 | 63 | 230 | 0 | 3250 | 0.00% | 49512.99 | 7639.7 | 8800.16 |
| 40% | 44m | 15700385 | 18 | 3 | 41 | 64 | 233 | 0 | 2083 | 0.00% | 50203.32 | 7746.22 | 8922.86 |
| 에코 | 1.9.2 | 16core16g | |||||||||||
| CPU | 메모리 | 샘플 | 평균 | 중앙값 | 90%라인 | 95%라인 | 99%라인 | 최소 | 맥스 | 오류% | 처리량 | KB/SEC를 받았습니다 | KB/SEC를 보내십시오 |
| 38% | 35m | 15307586 | 19 | 4 | 44 | 76 | 181 | 0 | 1808 | 0.00% | 48951.22 | 6166.71 | 9034.94 |
| 36% | 35m | 15239058 | 19 | 4 | 45 | 76 | 178 | 0 | 2003 | 0.00% | 48734.26 | 6139.37 | 8994.9 |
| 37% | 37m | 15800585 | 18 | 3 | 41 | 66 | 229 | 0 | 2355 | 0.00% | 50356.09 | 6343.68 | 9294.24 |
| 진 | 1.9.2 | 16core16g | |||||||||||
| CPU | 메모리 | 샘플 | 평균 | 중앙값 | 90%라인 | 95%라인 | 99%라인 | 최소 | 맥스 | 오류% | 처리량 | KB/SEC를 받았습니다 | KB/SEC를 보내십시오 |
| 36% | 36m | 15109143 | 19 | 6 | 44 | 71 | 175 | 0 | 3250 | 0.00% | 48151.87 | 5877.91 | 8746.33 |
| 36% | 40m | 15255749 | 19 | 5 | 43 | 70 | 189 | 0 | 3079 | 0.00% | 48762.53 | 5952.45 | 8857.25 |
| 36% | 40m | 15385401 | 18 | 4 | 42 | 66 | 227 | 0 | 2312 | 0.00% | 49181.03 | 6003.54 | 8933.27 |
Router . GET ( path string , handle HttpHandle )
Router . POST ( path string , handle HttpHandle )
Router . HEAD ( path string , handle HttpHandle )
Router . OPTIONS ( path string , handle HttpHandle )
Router . PUT ( path string , handle HttpHandle )
Router . PATCH ( path string , handle HttpHandle )
Router . DELETE ( path string , handle HttpHandle )
Router . HiJack ( path string , handle HttpHandle )
Router . WebSocket ( path string , handle HttpHandle )
Router . Any ( path string , handle HttpHandle )
Router . RegisterRoute ( routeMethod string , path string , handle HttpHandle )
Router . RegisterHandler ( name string , handler HttpHandle )
Router. GetHandler ( name string ) ( HttpHandle , bool )
Router . MatchPath ( ctx Context , routePath string ) bool두 개의 매개 변수를 허용합니다. 하나는 URI 경로이고 다른 하나는 httphandle 유형이며 경로와 일치 할 때 실행 방법을 설정합니다.
정적 라우팅 구문은 매개 변수가 없으며 패턴은 고정 문자열입니다.
package main
import (
"github.com/devfeel/dotweb"
)
func main () {
dotapp := dotweb . New ()
dotapp . HttpServer . GET ( "/hello" , func ( ctx dotweb. Context ) error {
return ctx . WriteString ( "hello world!" )
})
dotapp . StartServer ( 80 )
}테스트 : 컬 http://127.0.0.1/hello
매개 변수 라우팅 다음에 매개 변수 이름으로 문자열이 이어집니다. httpcontext의 getRoutoname 메소드를 통해 라우팅 매개 변수의 값을 얻을 수 있습니다.
package main
import (
"github.com/devfeel/dotweb"
)
func main () {
dotapp := dotweb . New ()
dotapp . HttpServer . GET ( "/hello/:name" , func ( ctx dotweb. Context ) error {
return ctx . WriteString ( "hello " + ctx . GetRouterName ( "name" ))
})
dotapp . HttpServer . GET ( "/news/:category/:newsid" , func ( ctx dotweb. Context ) error {
category := ctx . GetRouterName ( "category" )
newsid := ctx . GetRouterName ( "newsid" )
return ctx . WriteString ( "news info: category=" + category + " newsid=" + newsid )
})
dotapp . StartServer ( 80 )
} 시험:
컬 http://127.0.0.1/hello/devfeel
컬 http://127.0.0.1/hello/category1/1
g := server . Group ( "/user" )
g . GET ( "/" , Index )
g . GET ( "/profile" , Profile ) 시험:
컬 http://127.0.0.1/user
CURL http://127.0.0.1/user/profile
type UserInfo struct {
UserName string `form:"user"`
Sex int `form:"sex"`
}
func TestBind ( ctx dotweb. HttpContext ) error {
user := new ( UserInfo )
if err := ctx . Bind ( user ); err != nil {
return ctx . WriteString ( "err => " + err . Error ())
} else {
return ctx . WriteString ( "TestBind " + fmt . Sprint ( user ))
}
} app . Use ( NewAccessFmtLog ( "app" ))
func InitRoute ( server * dotweb. HttpServer ) {
server . GET ( "/" , Index )
server . GET ( "/use" , Index ). Use ( NewAccessFmtLog ( "Router-use" ))
g := server . Group ( "/group" ). Use ( NewAccessFmtLog ( "group" ))
g . GET ( "/" , Index )
g . GET ( "/use" , Index ). Use ( NewAccessFmtLog ( "group-use" ))
}
type AccessFmtLog struct {
dotweb. BaseMiddlware
Index string
}
func ( m * AccessFmtLog ) Handle ( ctx dotweb. Context ) error {
fmt . Println ( time . Now (), "[AccessFmtLog " , m . Index , "] begin request -> " , ctx . Request . RequestURI )
err := m . Next ( ctx )
fmt . Println ( time . Now (), "[AccessFmtLog " , m . Index , "] finish request " , err , " -> " , ctx . Request . RequestURI )
return err
}
func NewAccessFmtLog ( index string ) * AccessFmtLog {
return & AccessFmtLog { Index : index }
}httpserver.enabledsession
세션 지원을 활성화할지 여부를 설정하십시오. 현재 런타임 및 Redis 모드를 지원하며 기본적으로 활성화되지 않습니다.
httpserver.enabledgzip
GZIP 지원을 활성화할지 여부를 설정하면 기본적으로 활성화되지 않습니다.
httpserver.enabledlistdir
디렉토리 브라우징을 활성화할지 여부를 설정하면 router.serverfile에만 유효합니다. 이 항목을 설정하면 디렉토리 파일을 탐색 할 수 있으며 기본적으로 활성화되지 않습니다.
httpserver.enabledautohead
헤드 라우팅을 자동으로 활성화할지 여부를 설정하십시오. 이 항목이 설정되면 WebSocket Head를 제외한 모든 라우팅 방법에 대해 기본적으로 헤드 경로가 추가됩니다. 비 개발 모드는 기본적으로 활성화되지 않습니다.
httpserver.enableAutooptions
자동으로 옵션 라우팅을 활성화할지 여부를 설정하십시오. 이 항목이 설정되면 WebSocket Head를 제외한 모든 라우팅 방법에 대해 옵션 라우팅이 기본적으로 추가됩니다. 비 개발 모드는 기본적으로 활성화되지 않습니다.
httpserver.enabledignorefavicon
인터페이스 프로젝트에 일반적으로 사용되는 Favicon의 요청을 무시할지 여부
httpserver.enabledDetailRequestData
자세한 요청 데이터 통계를 활성화할지 여부를 설정하면 기본값이 False입니다. 이 항목이 설정되면 ServerStateInfo의 DetailRequestUrlData 통계가 활성화됩니다.
httpserver.enabledtls
TLS 암호화 처리를 활성화할지 여부를 설정하십시오
httpserver.enabledignorefavicon
Favicon 응답을 무시할지 여부를 설정하면 기본값은 False입니다. 이 항목이 설정되면 통합 된 무시 무시력이 기본적으로 등록되고 경로가 발효되기 전에 실행됩니다.
httpserver.enabledbindusejsontag
JSON 태그를 BIND 인터페이스에서 효과적으로 활성화할지 여부를 설정하면 기본값은 False입니다. 이 항목이 설정되면 Bind가 실행되면 JSON 태그가 확인됩니다.
type ExceptionHandle func ( Context , error ) type NotFoundHandle func (http. ResponseWriter , * http. Request ) WebSocket -Golang.org/x/net/websocket
Redis -github.com/garyburd/redigo
yaml -gopkg.in/yaml.v2
Go Mod에 의해 현재 관리되었습니다.
프로젝트 소개 : HTTP Long Connection Gateway Service, WebSocket 및 긴 폴링 서비스 제공
프로젝트 소개 : DotWeb 및 Mapper를 기반으로 한 GO 블로그 프로그램
프로젝트 소개 : DotWeb을 기반으로 한 GO 블로그 (블로그) 서버
프로젝트 소개 : 토큰 일관성 서비스 및 관련 글로벌 ID 생성 서비스 제공, 토큰 서비스 등.
프로젝트 소개 : WeChat Access Token Central Control Server는 다양한 공개 계정의 Access_tokens를 균일하게 관리하고 Access Token을 얻고 자동으로 새로 고침하기위한 통합 인터페이스를 제공하는 데 사용됩니다.
프로젝트 소개 : DotWeb, DotLog, Mapper, Dottask, Cache 및 Database를 기반으로하는 포괄적 인 프로젝트 템플릿.