本文整理汇总了Golang中github.com/openshift/origin/pkg/assets.GzipHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang GzipHandler函数的具体用法?Golang GzipHandler怎么用?Golang GzipHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GzipHandler函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildAssetHandler
func (c *AssetConfig) buildAssetHandler() (http.Handler, error) {
assets.RegisterMimeTypes()
publicURL, err := url.Parse(c.Options.PublicURL)
if err != nil {
glog.Fatal(err)
}
assetFunc := assets.JoinAssetFuncs(assets.Asset, java.Asset)
assetDirFunc := assets.JoinAssetDirFuncs(assets.AssetDir, java.AssetDir)
handler := http.FileServer(&assetfs.AssetFS{Asset: assetFunc, AssetDir: assetDirFunc, Prefix: ""})
// Map of context roots (no leading or trailing slash) to the asset path to serve for requests to a missing asset
subcontextMap := map[string]string{
"": "index.html",
"java": "java/index.html",
}
handler, err = assets.HTML5ModeHandler(publicURL.Path, subcontextMap, handler, assetFunc)
if err != nil {
return nil, err
}
// Cache control should happen after all Vary headers are added, but before
// any asset related routing (HTML5ModeHandler and FileServer)
handler = assets.CacheControlHandler(version.Get().GitCommit, handler)
// Gzip first so that inner handlers can react to the addition of the Vary header
handler = assets.GzipHandler(handler)
return handler, nil
}
示例2: buildHandler
func (c *AssetConfig) buildHandler() (http.Handler, error) {
assets.RegisterMimeTypes()
masterURL, err := url.Parse(c.Options.MasterPublicURL)
if err != nil {
return nil, err
}
publicURL, err := url.Parse(c.Options.PublicURL)
if err != nil {
glog.Fatal(err)
}
config := assets.WebConsoleConfig{
MasterAddr: masterURL.Host,
MasterPrefix: LegacyOpenShiftAPIPrefix, // TODO: change when the UI changes from v1beta3 to v1
KubernetesAddr: masterURL.Host,
KubernetesPrefix: KubernetesAPIPrefix,
OAuthAuthorizeURI: OpenShiftOAuthAuthorizeURL(masterURL.String()),
OAuthRedirectBase: c.Options.PublicURL,
OAuthClientID: OpenShiftWebConsoleClientID,
LogoutURI: c.Options.LogoutURL,
}
handler := http.FileServer(
&assetfs.AssetFS{
assets.Asset,
assets.AssetDir,
"",
},
)
// Map of context roots (no leading or trailing slash) to the asset path to serve for requests to a missing asset
subcontextMap := map[string]string{
"": "index.html",
"java": "java/index.html",
}
handler, err = assets.HTML5ModeHandler(publicURL.Path, subcontextMap, handler)
if err != nil {
return nil, err
}
// Cache control should happen after all Vary headers are added, but before
// any asset related routing (HTML5ModeHandler and FileServer)
handler = assets.CacheControlHandler(version.Get().GitCommit, handler)
// Generated config.js can not be cached since it changes depending on startup options
handler = assets.GeneratedConfigHandler(config, handler)
// Gzip first so that inner handlers can react to the addition of the Vary header
handler = assets.GzipHandler(handler)
return handler, nil
}
示例3: addHandlers
func (c *AssetConfig) addHandlers(mux *http.ServeMux) error {
assetHandler, err := c.buildAssetHandler()
if err != nil {
return err
}
publicURL, err := url.Parse(c.Options.PublicURL)
if err != nil {
return err
}
masterURL, err := url.Parse(c.Options.MasterPublicURL)
if err != nil {
return err
}
// Web console assets
mux.Handle(publicURL.Path, http.StripPrefix(publicURL.Path, assetHandler))
originResources := sets.NewString()
k8sResources := sets.NewString()
versions := []unversioned.GroupVersion{}
versions = append(versions, latest.Versions...)
versions = append(versions, klatest.ExternalVersions...)
deadOriginVersions := sets.NewString(configapi.DeadOpenShiftAPILevels...)
deadKubernetesVersions := sets.NewString(configapi.DeadKubernetesAPILevels...)
for _, version := range versions {
for kind := range api.Scheme.KnownTypes(version) {
if strings.HasSuffix(kind, "List") {
continue
}
resource, _ := meta.KindToResource(kind, false)
if latest.OriginKind(version.WithKind(kind)) {
if !deadOriginVersions.Has(version.String()) {
originResources.Insert(resource)
}
} else {
if !deadKubernetesVersions.Has(version.String()) {
k8sResources.Insert(resource)
}
}
}
}
commonResources := sets.NewString()
for _, r := range originResources.List() {
if k8sResources.Has(r) {
commonResources.Insert(r)
}
}
if commonResources.Len() > 0 {
return fmt.Errorf("Resources for kubernetes and origin types intersect: %v", commonResources.List())
}
// Generated web console config
config := assets.WebConsoleConfig{
MasterAddr: masterURL.Host,
MasterPrefix: OpenShiftAPIPrefix,
MasterResources: originResources.List(),
KubernetesAddr: masterURL.Host,
KubernetesPrefix: KubernetesAPIPrefix,
KubernetesResources: k8sResources.List(),
OAuthAuthorizeURI: OpenShiftOAuthAuthorizeURL(masterURL.String()),
OAuthRedirectBase: c.Options.PublicURL,
OAuthClientID: OpenShiftWebConsoleClientID,
LogoutURI: c.Options.LogoutURL,
LoggingURL: c.Options.LoggingPublicURL,
MetricsURL: c.Options.MetricsPublicURL,
}
configPath := path.Join(publicURL.Path, "config.js")
configHandler, err := assets.GeneratedConfigHandler(config)
if err != nil {
return err
}
mux.Handle(configPath, assets.GzipHandler(configHandler))
// Extension scripts
extScriptsPath := path.Join(publicURL.Path, "scripts/extensions.js")
extScriptsHandler, err := assets.ExtensionScriptsHandler(c.Options.ExtensionScripts, c.Options.ExtensionDevelopment)
if err != nil {
return err
}
mux.Handle(extScriptsPath, assets.GzipHandler(extScriptsHandler))
// Extension stylesheets
extStylesheetsPath := path.Join(publicURL.Path, "styles/extensions.css")
extStylesheetsHandler, err := assets.ExtensionStylesheetsHandler(c.Options.ExtensionStylesheets, c.Options.ExtensionDevelopment)
if err != nil {
return err
}
mux.Handle(extStylesheetsPath, assets.GzipHandler(extStylesheetsHandler))
// Extension files
for _, extConfig := range c.Options.Extensions {
extPath := path.Join(publicURL.Path, "extensions", extConfig.Name) + "/"
extHandler := assets.AssetExtensionHandler(extConfig.SourceDirectory, extPath, extConfig.HTML5Mode)
mux.Handle(extPath, http.StripPrefix(extPath, extHandler))
}
//.........这里部分代码省略.........
示例4: addHandlers
//.........这里部分代码省略.........
mux.Handle(publicURL.Path, http.StripPrefix(publicURL.Path, assetHandler))
originResources := sets.NewString()
k8sResources := sets.NewString()
versions := []unversioned.GroupVersion{}
versions = append(versions, registered.GroupOrDie(api.GroupName).GroupVersions...)
versions = append(versions, registered.GroupOrDie(kapi.GroupName).GroupVersions...)
deadOriginVersions := sets.NewString(configapi.DeadOpenShiftAPILevels...)
deadKubernetesVersions := sets.NewString(configapi.DeadKubernetesAPILevels...)
for _, version := range versions {
for kind := range kapi.Scheme.KnownTypes(version) {
if strings.HasSuffix(kind, "List") {
continue
}
resource, _ := meta.KindToResource(version.WithKind(kind))
if latest.OriginKind(version.WithKind(kind)) {
if !deadOriginVersions.Has(version.String()) {
originResources.Insert(resource.Resource)
}
} else {
if !deadKubernetesVersions.Has(version.String()) {
k8sResources.Insert(resource.Resource)
}
}
}
}
commonResources := sets.NewString()
for _, r := range originResources.List() {
if k8sResources.Has(r) {
commonResources.Insert(r)
}
}
if commonResources.Len() > 0 {
return nil, fmt.Errorf("Resources for kubernetes and origin types intersect: %v", commonResources.List())
}
// Generated web console config and server version
config := assets.WebConsoleConfig{
APIGroupAddr: masterURL.Host,
APIGroupPrefix: genericapiserver.APIGroupPrefix,
MasterAddr: masterURL.Host,
MasterPrefix: api.Prefix,
MasterResources: originResources.List(),
KubernetesAddr: masterURL.Host,
KubernetesPrefix: genericapiserver.DefaultLegacyAPIPrefix,
KubernetesResources: k8sResources.List(),
OAuthAuthorizeURI: OpenShiftOAuthAuthorizeURL(masterURL.String()),
OAuthTokenURI: OpenShiftOAuthTokenURL(masterURL.String()),
OAuthRedirectBase: c.Options.PublicURL,
OAuthClientID: OpenShiftWebConsoleClientID,
LogoutURI: c.Options.LogoutURL,
LoggingURL: c.Options.LoggingPublicURL,
MetricsURL: c.Options.MetricsPublicURL,
LimitRequestOverrides: c.LimitRequestOverrides,
}
kVersionInfo := kversion.Get()
oVersionInfo := oversion.Get()
versionInfo := assets.WebConsoleVersion{
KubernetesVersion: kVersionInfo.GitVersion,
OpenShiftVersion: oVersionInfo.GitVersion,
}
extensionProps := assets.WebConsoleExtensionProperties{
ExtensionProperties: extensionPropertyArray(c.Options.ExtensionProperties),
}
configPath := path.Join(publicURL.Path, "config.js")
configHandler, err := assets.GeneratedConfigHandler(config, versionInfo, extensionProps)
if err != nil {
return nil, err
}
mux.Handle(configPath, assets.GzipHandler(configHandler))
// Extension scripts
extScriptsPath := path.Join(publicURL.Path, "scripts/extensions.js")
extScriptsHandler, err := assets.ExtensionScriptsHandler(c.Options.ExtensionScripts, c.Options.ExtensionDevelopment)
if err != nil {
return nil, err
}
mux.Handle(extScriptsPath, assets.GzipHandler(extScriptsHandler))
// Extension stylesheets
extStylesheetsPath := path.Join(publicURL.Path, "styles/extensions.css")
extStylesheetsHandler, err := assets.ExtensionStylesheetsHandler(c.Options.ExtensionStylesheets, c.Options.ExtensionDevelopment)
if err != nil {
return nil, err
}
mux.Handle(extStylesheetsPath, assets.GzipHandler(extStylesheetsHandler))
// Extension files
for _, extConfig := range c.Options.Extensions {
extBasePath := path.Join(publicURL.Path, "extensions", extConfig.Name)
extPath := extBasePath + "/"
extHandler := assets.AssetExtensionHandler(extConfig.SourceDirectory, extPath, extConfig.HTML5Mode)
mux.Handle(extPath, http.StripPrefix(extBasePath, extHandler))
}
return mux, nil
}