本文整理汇总了Golang中net/http.StripPrefix函数的典型用法代码示例。如果您正苦于以下问题:Golang StripPrefix函数的具体用法?Golang StripPrefix怎么用?Golang StripPrefix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StripPrefix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewLightifyServer
func NewLightifyServer(lightifyAddr string) error {
err := golightify.NewLightifyBridge(lightifyAddr)
if err != nil {
log.Printf("Connection to lightify bridge failed: ", err.Error())
return err
}
mux := http.NewServeMux()
server := &http.Server{
Addr: ":8080",
Handler: mux,
}
mux.HandleFunc("/api/lights", lightsHandler)
mux.HandleFunc("/api/groups", groupsHandler)
mux.Handle("/api/lights/", http.StripPrefix("/api/lights/", lightHandler{}))
mux.Handle("/api/groups/", http.StripPrefix("/api/groups/", groupHandler{}))
log.Println("Listening... ", server.Addr)
err = server.ListenAndServe()
if err != nil {
log.Printf("Server failed: ", err.Error())
return err
}
return nil
}
示例2: New
// New creates a new APIServer object.
// 'storage' contains a map of handlers.
// 'prefix' is the hosting path prefix.
func New(storage map[string]RESTStorage, prefix string) *APIServer {
s := &APIServer{
storage: storage,
prefix: strings.TrimRight(prefix, "/"),
ops: NewOperations(),
mux: http.NewServeMux(),
// Delay just long enough to handle most simple write operations
asyncOpWait: time.Millisecond * 25,
}
// Primary API methods
s.mux.HandleFunc(s.prefix+"/", s.handleREST)
s.mux.HandleFunc(s.watchPrefix()+"/", s.handleWatch)
// Support services for the apiserver
s.mux.Handle("/logs/", http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log/"))))
healthz.InstallHandler(s.mux)
s.mux.HandleFunc("/version", handleVersion)
s.mux.HandleFunc("/", handleIndex)
// Handle both operations and operations/* with the same handler
s.mux.HandleFunc(s.operationPrefix(), s.handleOperation)
s.mux.HandleFunc(s.operationPrefix()+"/", s.handleOperation)
// Proxy minion requests
s.mux.Handle("/proxy/minion/", http.StripPrefix("/proxy/minion", http.HandlerFunc(handleProxyMinion)))
return s
}
示例3: main
func main() {
if err := goa.Init(goa.Config{
LoginPage: "/login.html",
HashKey: []byte(hashKey),
EncryptionKey: []byte(cryptoKey),
CookieName: "session",
PQConfig: "user=test_user password=test_pass dbname=goa",
}); err != nil {
log.Println(err)
return
}
// public (no-auth-required) files
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public"))))
// protected files, only for logged-in users
http.Handle("/protected/", goa.NewHandler(http.StripPrefix("/protected/", http.FileServer(http.Dir("protected")))))
// home handler
http.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
http.ServeFile(rw, req, "index.html")
})
http.HandleFunc("/login.html", func(rw http.ResponseWriter, req *http.Request) {
http.ServeFile(rw, req, "login.html")
})
http.HandleFunc("/register.html", func(rw http.ResponseWriter, req *http.Request) {
http.ServeFile(rw, req, "register.html")
})
if err := http.ListenAndServeTLS(":8080", "keys/cert.pem", "keys/key.pem", nil); err != nil {
log.Println(err)
}
}
示例4: main
func main() {
var portNumber int
flag.IntVar(&portNumber, "port", 80, "Default port is 80")
flag.Parse()
// Routes to serve front-end assets
r := mux.NewRouter()
http.Handle("/javascripts/", http.StripPrefix("/javascripts/", http.FileServer(http.Dir("frontend/public/javascripts/"))))
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("frontend/public/images/"))))
http.Handle("/stylesheets/", http.StripPrefix("/stylesheets/", http.FileServer(http.Dir("frontend/public/stylesheets/"))))
// API Endpoints
r.PathPrefix(V1_PREFIX + "/run-ad-on/{service}/for/{stream}").HandlerFunc(ads.AdRequester)
r.Path(V1_PREFIX + "/ping").HandlerFunc(health.Ping)
// Pass to front-end
r.PathPrefix(V1_PREFIX + "/stream").HandlerFunc(index)
r.PathPrefix(V1_PREFIX).HandlerFunc(index)
http.Handle("/", r)
port := strconv.FormatInt(int64(portNumber), 10)
fmt.Println("IRWIn Server starting")
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatalf("Could not start on port "+port, err)
}
}
示例5: main
func main() {
http.HandleFunc("/", index)
http.HandleFunc("/up", upload)
http.HandleFunc("/del", delfile)
http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("static"))))
http.Handle("/i/", http.StripPrefix("/i", http.FileServer(http.Dir("i"))))
config = readConfig()
validateConfig(config)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
if config.Http.Enabled {
log.Printf("Starting HTTP server on %s\n", config.Http.Listen)
log.Println(http.ListenAndServe(config.Http.Listen, nil))
}
}()
go func() {
defer wg.Done()
if config.Https.Enabled {
log.Printf("Starting HTTPS server on %s\n", config.Https.Listen)
log.Println(http.ListenAndServeTLS(config.Https.Listen, config.Https.Cert, config.Https.Key, nil))
}
}()
wg.Wait()
}
示例6: InstallSupport
// InstallSupport registers the APIServer support functions into a mux.
func InstallSupport(mux mux) {
healthz.InstallHandler(mux)
mux.Handle("/logs/", http.StripPrefix("/logs/", http.FileServer(http.Dir("/var/log/"))))
mux.Handle("/proxy/minion/", http.StripPrefix("/proxy/minion", http.HandlerFunc(handleProxyMinion)))
mux.HandleFunc("/version", handleVersion)
mux.HandleFunc("/", handleIndex)
}
示例7: main
func main() {
flag.Parse()
s, err := susigo.NewSusi(*susiaddr, *cert, *key)
if err != nil {
log.Printf("Error while creating susi connection: %v", err)
return
}
susi = s
log.Println("successfully create susi connection")
sessionTimeouts = make(map[string]time.Time)
if *user == "" && *pass == "" {
http.HandleFunc("/publish", publishHandler)
http.HandleFunc("/upload", uploadHandler)
http.Handle("/ws", websocket.Handler(websocketHandler))
http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir(*assetDir))))
http.HandleFunc("/", redirectToIndex)
} else {
http.HandleFunc("/publish", BasicAuth(publishHandler))
http.HandleFunc("/upload", BasicAuth(uploadHandler))
http.HandleFunc("/ws", BasicAuth(websocket.Handler(websocketHandler).ServeHTTP))
http.HandleFunc("/assets/", BasicAuth(http.StripPrefix("/assets/", http.FileServer(http.Dir(*assetDir))).ServeHTTP))
http.HandleFunc("/", BasicAuth(redirectToIndex))
}
log.Printf("starting http server on %v...", *webaddr)
if *useHTTPS {
log.Fatal(http.ListenAndServeTLS(*webaddr, *cert, *key, context.ClearHandler(http.DefaultServeMux)))
} else {
log.Fatal(http.ListenAndServe(*webaddr, context.ClearHandler(http.DefaultServeMux)))
}
}
示例8: main
func main() {
err := LoadConfig()
if err != nil {
log.Fatal("Could not load config file hidemyemail.cfg")
return
}
g_conn_string = g_config.DbConnectionString
http.Handle("/captcha/", captcha.Server(captcha.StdWidth, captcha.StdHeight))
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir(g_config.ResourcePath+"/images"))))
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir(g_config.ResourcePath+"/css"))))
http.HandleFunc("/add",
func(w http.ResponseWriter, r *http.Request) {
handleAdd(w, r)
})
http.HandleFunc("/get",
func(w http.ResponseWriter, r *http.Request) {
handleGet(w, r)
})
http.HandleFunc("/",
func(w http.ResponseWriter, r *http.Request) {
handleGetCaptcha(w, r)
})
log.Fatal(http.ListenAndServe(":"+g_config.Port, nil))
}
示例9: main
func main() {
//Have to add handles for serving static pages, still a bit fuzzy on the FileServer stuff.
http.Handle("/pic/", http.StripPrefix("/pic/", http.FileServer(http.Dir("pic"))))
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
http.HandleFunc("/", handleThis)
http.ListenAndServe(":8000", nil)
}
示例10: main
func main() {
db.DB, err = sql.Open("postgres", config.GetValue("DATABASE_URL"))
defer db.DB.Close()
if err != nil {
log.Fatalln("Error DB open:", err.Error())
}
if err = db.DB.Ping(); err != nil {
log.Fatalln("Error DB ping:", err.Error())
}
log.Println("Connected to DB")
testData := flag.Bool("test-data", false, "to load test data")
resetDB := flag.Bool("reset-db", false, "reset the database")
flag.Parse()
initial.Init(*resetDB, *testData)
// base := new(controllers.BaseController)
// base.Index().LoadContestsFromCats()
http.Handle("/", new(router.FastCGIServer))
http.HandleFunc("/wellcometoprofile/", controllers.WellcomeToProfile)
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./static/js"))))
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./static/css"))))
http.Handle("/img/", http.StripPrefix("/img/", http.FileServer(http.Dir("./static/img"))))
addr := config.GetValue("HOSTNAME") + ":" + config.GetValue("PORT")
log.Println("Server listening on", addr)
log.Fatalln("Error listening:", http.ListenAndServe(addr, nil))
}
示例11: main
func main() {
fs := filesystem.New("articles")
recv := make(chan request, 5)
for i := 0; i < 4; i++ {
go handleRequests(fs, recv)
}
// Serve websocket article requests.
http.HandleFunc("/ws", serveWs(recv))
// Serve http article requests.
articleHandler := httpArticleHandler{recv}
http.Handle("/article/", http.StripPrefix("/article/", &articleHandler))
// Serve front page.
http.HandleFunc("/",
func(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, "front.html")
})
// Serve static content.
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./css"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./js"))))
http.Handle("/fonts/", http.StripPrefix("/fonts/", http.FileServer(http.Dir("./fonts"))))
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}
示例12: main
func main() {
if len(os.Args) != 2 {
fmt.Fprint(os.Stderr, "Usage: ", os.Args[0], ":port\n")
os.Exit(1)
}
port := os.Args[1]
// dictionaryPath := "/var/www/go/chinese/cedict_ts.u8"
dictionaryPath := "cedict_ts.u8"
d = new(dictionary.Dictionary)
d.Load(dictionaryPath)
fmt.Println("Loaded dict", len(d.Entries))
http.HandleFunc("/", listFlashCards)
//fileServer := http.FileServer("/var/www/go/chinese/jscript", "/jscript/")
fileServer := http.StripPrefix("/jscript/", http.FileServer(http.Dir("jscript")))
http.Handle("/jscript/", fileServer)
// fileServer = http.FileServer("/var/www/go/chinese/html", "/html/")
fileServer = http.StripPrefix("/html/", http.FileServer(http.Dir("html")))
http.Handle("/html/", fileServer)
http.HandleFunc("/wordlook", lookupWord)
http.HandleFunc("/flashcards.html", listFlashCards)
http.HandleFunc("/flashcardSets", manageFlashCards)
http.HandleFunc("/searchWord", searchWord)
http.HandleFunc("/addWord", addWord)
http.HandleFunc("/newFlashCardSet", newFlashCardSet)
// deliver requests to the handlers
err := http.ListenAndServe(port, nil)
checkError(err)
// That's it!
}
示例13: main
func main() {
http.HandleFunc("/hello", hello)
http.Handle(
"/example/",
http.StripPrefix(
"/example/",
http.FileServer(http.Dir("example")),
),
)
http.Handle(
"/chksum/",
http.StripPrefix(
"/chksum/",
http.FileServer(http.Dir("chksum")),
),
)
http.Handle(
"/all/",
http.StripPrefix(
"/all/",
http.FileServer(http.Dir(".")),
),
)
http.ListenAndServe(":9000", nil)
}
示例14: init
func init() {
//html files, and strips prefixes for img and css
tpl, _ = template.ParseGlob("*.html")
http.HandleFunc("/", main)
http.Handle("/css/", http.StripPrefix("/css", http.FileServer(http.Dir("css"))))
http.Handle("/img/", http.StripPrefix("/img", http.FileServer(http.Dir("img"))))
}
示例15: main
func main() {
dashr_ip := flag.String("fqdn", "127.0.0.1", "IP/FQDN to run HTTP listener at")
dashr_port := flag.String("http", "8001", "port to run HTTP listener at")
www_data := flag.String("www", "www-data", "path to ansible dashr static site content")
ansible_setup := flag.String("ansible", "dummy-ansible-files", "path to ansible setup root of Playbooks, Roles Dir")
dashr_config := flag.String("config", "config", "path to fetch/save Config used by Static Site Content")
flag.Parse()
connection_string := fmt.Sprintf("%s:%s", *dashr_ip, *dashr_port)
www_data_uri := fmt.Sprintf("/%s/", *www_data)
ansible_setup_uri := fmt.Sprintf("/%s/", *ansible_setup)
dashr_config_uri := fmt.Sprintf("/%s/", *dashr_config)
dashr_fs := http.FileServer(http.Dir(*www_data))
http.Handle(www_data_uri, http.StripPrefix(www_data_uri, dashr_fs))
ansible_fs := http.FileServer(http.Dir(*ansible_setup))
http.Handle(ansible_setup_uri, http.StripPrefix(ansible_setup_uri, ansible_fs))
config_fs := http.FileServer(http.Dir(*dashr_config))
http.Handle(dashr_config_uri, http.StripPrefix(dashr_config_uri, config_fs))
http.HandleFunc("/", redirect)
log.Println("Ansible Dashr @", connection_string)
if err := http.ListenAndServe(connection_string, nil); err != nil {
fmt.Println("ERROR: Failed to start server.", err.Error())
}
}