/
index.go
47 lines (42 loc) · 1.07 KB
/
index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2015 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package api
import (
"html/template"
"net/http"
"path"
"github.com/tsuru/config"
)
// title: index
// path: /
// method: GET
// responses:
//
// 200: OK
func index(w http.ResponseWriter, r *http.Request) error {
host, _ := config.GetString("host")
userCreate, _ := config.GetBool("auth:user-registration")
scheme, _ := config.GetString("auth:scheme")
data := map[string]interface{}{
"tsuruTarget": host,
"userCreate": userCreate,
"nativeLogin": scheme == "" || scheme == "native",
}
template, err := getTemplate()
if err != nil {
return err
}
return template.Execute(w, data)
}
func getTemplate() (*template.Template, error) {
templateFile, _ := config.GetString("index-page-template")
if templateFile == "" {
return indexTemplate, nil
}
tmpl, err := template.New("index").Funcs(funcMap).ParseFiles(templateFile)
if err != nil {
return nil, err
}
return tmpl.Lookup(path.Base(templateFile)), nil
}