This repository was archived by the owner on Jan 23, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-16
lines changed
Expand file tree Collapse file tree 2 files changed +17
-16
lines changed Original file line number Diff line number Diff line change 44DOR - Domain Ranker
55-------------------
66
7- Fast HTTP service (build on top of amazing
8- [ iris framework] ( https://github.com/kataras/iris ) ) which shows a specified
9- domain rank from following providers:
7+ Fast HTTP service which shows a specified domain rank from following providers:
108- [ Alexa] ( https://www.alexa.com/topsites )
119- [ Majestic] ( https://blog.majestic.com/development/alexa-top-1-million-sites-retired-heres-majestic-million/ )
1210- [ Umbrella OpenDNS] ( https://umbrella.cisco.com/blog/2016/12/14/cisco-umbrella-1-million/ )
@@ -53,10 +51,8 @@ Or if you want just in-memory database:
5351dor-web-inmemory -h
5452
5553Usage of dor-web-inmemory:
56- -host string
57- IP-address to bind (default "127.0.0.1")
58- -port string
59- Port to bind (default "8080")
54+ -listen string
55+ Listen address to bind (default "127.0.0.1:8080")
6056```
6157
6258## Docker usage
Original file line number Diff line number Diff line change 11package dorweb
22
33import (
4+ "encoding/json"
45 "log"
6+ "net/http"
57
68 "github.com/ilyaglow/dor"
7- "github.com/kataras/iris "
9+ "github.com/julienschmidt/httprouter "
810)
911
1012// Serve represents a web interaction with the DomainRank
1113func Serve (address string , d * dor.App ) {
12- app := iris .New ()
13- app . Get ("/rank/{domain:string} " , func (ctx iris. Context ) {
14- r , err := d .Find (ctx . Params (). Get ("domain" ))
14+ router := httprouter .New ()
15+ router . GET ("/rank/:domain " , func (w http. ResponseWriter , r * http. Request , ps httprouter. Params ) {
16+ result , err := d .Find (ps . ByName ("domain" ))
1517 if err != nil {
16- ctx .StatusCode (iris .StatusBadRequest )
17- } else {
18- ctx .JSON (r )
18+ http .Error (w , err .Error (), http .StatusBadRequest )
19+ return
1920 }
20- })
2121
22- log .Fatal (app .Run (iris .Addr (address ), iris .WithCharset ("UTF-8" )))
22+ enc := json .NewEncoder (w )
23+ if err := enc .Encode (result ); err != nil {
24+ http .Error (w , err .Error (), http .StatusInternalServerError )
25+ }
26+ })
27+ log .Fatal (http .ListenAndServe (address , router ))
2328}
You can’t perform that action at this time.
0 commit comments