本文整理汇总了Golang中mime.AddExtensionType函数的典型用法代码示例。如果您正苦于以下问题:Golang AddExtensionType函数的具体用法?Golang AddExtensionType怎么用?Golang AddExtensionType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddExtensionType函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
// Silence log output
log.SetOutput(nil)
// setup mime
mime.AddExtensionType(".foo", "foo/bar")
mime.AddExtensionType(".json", "application/json")
mime.AddExtensionType(".txt", "text/plain")
mime.AddExtensionType(".png", "image/png")
mime.AddExtensionType(".html", "text/html")
go func() {
// falcore setup
pipeline := falcore.NewPipeline()
pipeline.Upstream.PushBack(&FileFilter{
PathPrefix: "/",
BasePath: "../test/",
DirectoryIndex: "index.html",
})
srv = falcore.NewServer(0, pipeline)
if err := srv.ListenAndServe(); err != nil {
panic(fmt.Sprintf("Could not start falcore: %v", err))
}
}()
}
示例2: init
func init() {
if err := mime.AddExtensionType(".rmvb", "application/vnd.rn-realmedia-vbr"); err != nil {
panic(err)
}
if err := mime.AddExtensionType(".ogv", "video/ogg"); err != nil {
panic(err)
}
}
示例3: main
func main() {
// beego.AutoRender = false
beego.ViewsPath = "tpl" //模板存储目录
beego.SessionOn = true //SESSION开启
mime.AddExtensionType(".css", "text/css") //CSS 输出页头Content-Type
mime.AddExtensionType(".js", "application/javascript") //JS 输出页头Content-Type
beego.SetStaticPath("/static", "static") //注册静态文件目录
beego.Errorhandler("404", page404)
beego.Run()
}
示例4: init
func init() {
// Add some types we want to be able to handle which can be missing by default
mime.AddExtensionType(".json", "application/json")
mime.AddExtensionType(".yml", "application/yaml")
mime.AddExtensionType(".yaml", "application/yaml")
sourceReaders = make(map[string]func(*Source) ([]byte, error))
// Register our source-reader functions
addSourceReader("http", readHTTP)
addSourceReader("https", readHTTP)
addSourceReader("file", readFile)
}
示例5: initServer
func (s *Server) initServer() {
if s.Config == nil {
s.Config = &ServerConfig{}
}
if s.Logger == nil {
s.Logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
}
// Set two commonly used mimetypes that are often not set by default
// Handy for robots.txt and favicon.ico
mime.AddExtensionType(".txt", "text/plain; charset=utf-8")
mime.AddExtensionType(".ico", "image/x-icon")
}
示例6: MimeType
func MimeType(args []string) {
filename := args[0]
ext := filepath.Ext(filename)
mime.AddExtensionType(".gz", "application/gzip")
mime.AddExtensionType(".tgz", "application/gzip")
mime.AddExtensionType(".tar", "application/tar")
mime.AddExtensionType(".zip", "application/zip")
mimetype := mime.TypeByExtension(ext)
if mimetype != "" {
fmt.Println(mimetype)
} else {
fmt.Println("application/octet-stream")
}
}
示例7: start
// Setup all routers, handlers and start a HTTP server (blocking call)
func (api *RESTfulAPI) start(catalogStorage catalog.CatalogStorage) {
api.mountCatalog(catalogStorage)
api.mountResources()
api.router.Methods("GET", "POST").Path("/dashboard").HandlerFunc(api.dashboardHandler(*confPath))
api.router.Methods("GET").Path(api.restConfig.Location).HandlerFunc(api.indexHandler())
err := mime.AddExtensionType(".jsonld", "application/ld+json")
if err != nil {
logger.Println("RESTfulAPI.start() ERROR:", err.Error())
}
// Configure the middleware
n := negroni.New(
negroni.NewRecovery(),
negroni.NewLogger(),
&negroni.Static{
Dir: http.Dir(api.config.StaticDir),
Prefix: StaticLocation,
IndexFile: "index.html",
},
)
// Mount router
n.UseHandler(api.router)
// Start the listener
addr := fmt.Sprintf("%v:%v", api.config.Http.BindAddr, api.config.Http.BindPort)
logger.Printf("RESTfulAPI.start() Starting server at http://%v%v", addr, api.restConfig.Location)
n.Run(addr)
}
示例8: init
func init() {
// add missing extensions
for k, v := range mimeRdfExt {
mime.AddExtensionType(k, v)
}
for _, syntax := range crdf.ParserSyntax {
switch syntax.MimeType {
case "", "text/html":
continue
}
mimeParser[syntax.MimeType] = syntax.Name
}
mimeParser["text/n3"] = mimeParser["text/turtle"]
for name, syntax := range crdf.SerializerSyntax {
switch name {
case "json-triples":
// only activate: json
continue
case "rdfxml-xmp", "rdfxml":
// only activate: rdfxml-abbrev
continue
}
mimeSerializer[syntax.MimeType] = syntax.Name
}
for mime := range mimeSerializer {
switch mime {
case "application/xhtml+xml":
continue
}
serializerMimes = append(serializerMimes, mime)
}
}
示例9: Serve
func Serve(httpAddress *string, db core.Database, s *search.Searcher, devAssets bool, updater *torrent.StatsUpdater) {
// Add SVG to mime directory
mime.AddExtensionType(".svg", "image/svg+xml")
r := mux.NewRouter()
apirouter := ApiRouter(db, s, updater)
r.PathPrefix("/api/").Handler(apirouter)
if devAssets {
log.Println("Debug mode is on. Serving development assets from angular/app.")
r.PathPrefix("/styles/").Handler(http.FileServer(http.Dir("frontend/angular/.tmp/")))
r.PathPrefix("/bower_components/").Handler(http.FileServer(http.Dir("frontend/angular/")))
r.PathPrefix("/").Handler(NotFoundHook{
http.FileServer(http.Dir("frontend/angular/app/")),
"frontend/angular/app/index.html"})
} else {
r.PathPrefix("/").Handler(NotFoundHook{
http.FileServer(http.Dir("frontend/angular/dist/")),
"frontend/angular/dist/index.html"})
}
http.Handle("/", r)
log.Println("Web server listening on", *httpAddress)
err := http.ListenAndServe(*httpAddress, nil)
if err != nil {
log.Println(err)
}
}
示例10: init
func init() {
playScript(basePath, "HTTPTransport")
present.PlayEnabled = true
// App Engine has no /etc/mime.types
mime.AddExtensionType(".svg", "image/svg+xml")
}
示例11: init
func init() {
initHugoBuilderFlags(serverCmd)
serverCmd.Flags().IntVarP(&serverPort, "port", "p", 1313, "port on which the server will listen")
serverCmd.Flags().StringVarP(&serverInterface, "bind", "", "127.0.0.1", "interface to which the server will bind")
serverCmd.Flags().BoolVarP(&serverWatch, "watch", "w", true, "watch filesystem for changes and recreate as needed")
serverCmd.Flags().BoolVarP(&serverAppend, "appendPort", "", true, "append port to baseurl")
serverCmd.Flags().BoolVar(&disableLiveReload, "disableLiveReload", false, "watch without enabling live browser reload on rebuild")
serverCmd.Flags().BoolVar(&renderToDisk, "renderToDisk", false, "render to Destination path (default is render to memory & serve from there)")
serverCmd.Flags().String("memstats", "", "log memory usage to this file")
serverCmd.Flags().Int("meminterval", 100, "interval to poll memory usage (requires --memstats)")
serverCmd.RunE = server
mime.AddExtensionType(".json", "application/json; charset=utf-8")
mime.AddExtensionType(".css", "text/css; charset=utf-8")
}
示例12: main
func main() {
mime.AddExtensionType(".ico", "image/x-icon")
mime.AddExtensionType(".svg", "image/svg+xml")
fileHandler := http.FileServer(http.Dir("/content"))
http.Handle("/", loggingHandler(fileHandler))
go func() {
log.Println("Starting up at :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}()
// Handle SIGTERM.
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGTERM)
log.Printf("Received signal '%v'. Exiting.", <-ch)
}
示例13: init
func init() {
initTemplates("./present/")
present.PlayEnabled = true
initPlayground("./present/", nil)
// App Engine has no /etc/mime.types
mime.AddExtensionType(".svg", "image/svg+xml")
}
示例14: init
func init() {
mime.AddExtensionType(".dart", "application/dart")
fs := http.FileServer(http.Dir("app/build/web"))
http.Handle("/", fs)
//router.Run(":8080")
//http.ListenAndServe(":8080", nil)
}
示例15: init
// Register all the mimes in types.go
func init() {
for _, v := range mimes {
err := mime.AddExtensionType(v.Extension, v.Type)
if err != nil {
log.Println(err)
}
}
}