Skip to content

Commit 4c023f6

Browse files
committed
performance optimization
1 parent 424f7fa commit 4c023f6

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

modules/auth/sso/sspi_windows.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,26 @@ var (
4040
// On successful authentication returns a valid user object.
4141
// Returns nil if authentication fails.
4242
type SSPI struct {
43+
rnd *render.Render
4344
}
4445

4546
// Init creates a new global websspi.Authenticator object
4647
func (s *SSPI) Init() error {
4748
config := websspi.NewConfig()
4849
var err error
4950
sspiAuth, err = websspi.New(config)
50-
return err
51+
if err != nil {
52+
return err
53+
}
54+
s.rnd = render.New(render.Options{
55+
Extensions: []string{".tmpl"},
56+
Directory: "templates",
57+
Funcs: templates.NewFuncMap(),
58+
Asset: templates.GetAsset,
59+
AssetNames: templates.GetAssetNames,
60+
IsDevelopment: setting.RunMode != "prod",
61+
})
62+
return nil
5163
}
5264

5365
// Free releases resources used by the global websspi.Authenticator object
@@ -86,19 +98,10 @@ func (s *SSPI) VerifyAuthData(req *http.Request, w http.ResponseWriter, store Da
8698
store.GetData()["Flash"] = map[string]string{
8799
"ErrMsg": err.Error(),
88100
}
89-
90101
store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
91102
store.GetData()["EnableSSPI"] = true
92103

93-
rnd := render.New(render.Options{
94-
Extensions: []string{".tmpl"},
95-
Directory: "templates",
96-
Funcs: templates.NewFuncMap(),
97-
Asset: templates.GetAsset,
98-
AssetNames: templates.GetAssetNames,
99-
IsDevelopment: setting.RunMode != "prod",
100-
})
101-
err := rnd.HTML(w, 401, string(tplSignIn), templates.BaseVars().Merge(store.GetData()))
104+
err := s.rnd.HTML(w, 401, string(tplSignIn), templates.BaseVars().Merge(store.GetData()))
102105
if err != nil {
103106
log.Error("%v", err)
104107
}

0 commit comments

Comments
 (0)