github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/net/http/repo/register_handlers.go (about)

     1  package repo
     2  
     3  import (
     4  	"bytes"
     5  	"net/http"
     6  
     7  	"github.com/pbberlin/tools/net/http/htmlfrag"
     8  	"github.com/pbberlin/tools/net/http/loghttp"
     9  	"github.com/pbberlin/tools/net/http/routes"
    10  )
    11  
    12  // InitHandlers is called from outside,
    13  // and makes the EndPoints available.
    14  func InitHandlers() {
    15  	http.HandleFunc(uriSetType, loghttp.Adapter(setFSType))
    16  
    17  	http.HandleFunc("/fetch/request-static", loghttp.Adapter(staticFetchDirect))
    18  
    19  	http.HandleFunc(uriFetchCommandSender, loghttp.Adapter(staticFetchViaPosting2Receiver))
    20  	http.HandleFunc(uriFetchCommandReceiver, loghttp.Adapter(fetchCommandReceiver))
    21  
    22  	http.HandleFunc(UriMountNameY, loghttp.Adapter(serveFile))
    23  
    24  	// working only for memfs
    25  	http.Handle("/fetch/reservoire/static/", http.StripPrefix("/fetch/reservoire/static/", fileserver1))
    26  
    27  	http.Handle(routes.FetchSimilarURI, loghttp.Adapter(FetchSimilar))
    28  	http.Handle("/fetch/similiar/form/", loghttp.Adapter(fetchSimForm))
    29  
    30  }
    31  
    32  // BackendUIRendered returns a userinterface rendered to HTML
    33  func BackendUIRendered() *bytes.Buffer {
    34  	var b1 = new(bytes.Buffer)
    35  	htmlfrag.Wb(b1, "Fetcher", "")
    36  	htmlfrag.Wb(b1, "type", uriSetType, "storage type")
    37  
    38  	htmlfrag.Wb(b1, "static command", "/fetch/request-static", "send direct")
    39  
    40  	htmlfrag.Wb(b1, "send command", uriFetchCommandSender, "dynamic")
    41  
    42  	sample := "www.economist.com/news/europe/21661810-journey-capital-hinterland-shows-how-grim-life-has-become-and-how-russians"
    43  	htmlfrag.Wb(b1, "get similar", routes.FetchSimilarURI+"?"+routes.URLParamKey+"="+sample+"&cnt=2", "similar to url x")
    44  	htmlfrag.Wb(b1, "  form", "/fetch/similiar/form/")
    45  
    46  	htmlfrag.Wb(b1, "recv", uriFetchCommandReceiver, "receive fetch command, takes commands by curl")
    47  
    48  	htmlfrag.Wb(b1, "reservoire BOTH", UriMountNameY+"?fmt=html", "browse ANY fsi.FileSystem - human readable with ?fmt=http ")
    49  
    50  	htmlfrag.Wb(b1, "reservoire static", "/fetch/reservoire/static/", "browse - memfs only")
    51  
    52  	return b1
    53  }