mirror of https://github.com/statping/statping
http header panic fix - cache in settings
parent
60262f75f9
commit
8825f836e8
|
@ -14,6 +14,7 @@ type Cacher interface {
|
||||||
Get(key string) []byte
|
Get(key string) []byte
|
||||||
Delete(key string)
|
Delete(key string)
|
||||||
Set(key string, content []byte, duration time.Duration)
|
Set(key string, content []byte, duration time.Duration)
|
||||||
|
List() map[string]Item
|
||||||
}
|
}
|
||||||
|
|
||||||
// Item is a cached reference
|
// Item is a cached reference
|
||||||
|
@ -44,6 +45,10 @@ func NewStorage() *Storage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Storage) List() map[string]Item {
|
||||||
|
return s.items
|
||||||
|
}
|
||||||
|
|
||||||
//Get a cached content by key
|
//Get a cached content by key
|
||||||
func (s Storage) Get(key string) []byte {
|
func (s Storage) Get(key string) []byte {
|
||||||
item := s.items[key]
|
item := s.items[key]
|
||||||
|
|
|
@ -82,6 +82,9 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
|
||||||
"Error": func() string {
|
"Error": func() string {
|
||||||
return ""
|
return ""
|
||||||
},
|
},
|
||||||
|
"Cache": func() Cacher {
|
||||||
|
return CacheStorage
|
||||||
|
},
|
||||||
"ToString": func(v interface{}) string {
|
"ToString": func(v interface{}) string {
|
||||||
return utils.ToString(v)
|
return utils.ToString(v)
|
||||||
},
|
},
|
||||||
|
@ -98,6 +101,12 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
|
||||||
"FromUnix": func(t int64) string {
|
"FromUnix": func(t int64) string {
|
||||||
return utils.Timezoner(time.Unix(t, 0), core.CoreApp.Timezone).Format("Monday, January 02")
|
return utils.Timezoner(time.Unix(t, 0), core.CoreApp.Timezone).Format("Monday, January 02")
|
||||||
},
|
},
|
||||||
|
"UnixTime": func(t int64, nano bool) string {
|
||||||
|
if nano {
|
||||||
|
t = t / 1e9
|
||||||
|
}
|
||||||
|
return utils.Timezoner(time.Unix(t, 0), core.CoreApp.Timezone).String()
|
||||||
|
},
|
||||||
"NewService": func() *types.Service {
|
"NewService": func() *types.Service {
|
||||||
return new(types.Service)
|
return new(types.Service)
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
|
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
|
||||||
<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true"><i class="fa fa-cogs"></i> Settings</a>
|
<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true"><i class="fa fa-cogs"></i> Settings</a>
|
||||||
<a class="nav-link" id="v-pills-style-tab" data-toggle="pill" href="#v-pills-style" role="tab" aria-controls="v-pills-style" aria-selected="false"><i class="fa fa-image"></i> Theme Editor</a>
|
<a class="nav-link" id="v-pills-style-tab" data-toggle="pill" href="#v-pills-style" role="tab" aria-controls="v-pills-style" aria-selected="false"><i class="fa fa-image"></i> Theme Editor</a>
|
||||||
|
<a class="nav-link" id="v-pills-cache-tab" data-toggle="pill" href="#v-pills-cache" role="tab" aria-controls="v-pills-cache" aria-selected="false"><i class="fa fa-paperclip"></i> Cache</a>
|
||||||
{{ range .Notifications }}
|
{{ range .Notifications }}
|
||||||
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Select.Method}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Select.Method}}" role="tab" aria-controls="v-pills-{{underscore .Select.Method}}" aria-selected="false"><i class="{{.Select.Icon}}"></i> {{.Select.Method}}</a>
|
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Select.Method}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Select.Method}}" role="tab" aria-controls="v-pills-{{underscore .Select.Method}}" aria-selected="false"><i class="{{.Select.Icon}}"></i> {{.Select.Method}}</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -125,7 +126,6 @@
|
||||||
<h3>Additional Settings</h3>
|
<h3>Additional Settings</h3>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a href="/api/clear_cache" class="btn btn-sm btn-secondary float-right">Clear Cache</a>
|
|
||||||
<a href="/settings/export" class="btn btn-sm btn-secondary float-right">Export Settings</a>
|
<a href="/settings/export" class="btn btn-sm btn-secondary float-right">Export Settings</a>
|
||||||
{{if .Domain}}
|
{{if .Domain}}
|
||||||
<a href="#" class="btn btn-sm btn-secondary float-right ml-1">Authentication QR Code</a>
|
<a href="#" class="btn btn-sm btn-secondary float-right ml-1">Authentication QR Code</a>
|
||||||
|
@ -180,6 +180,28 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-pane" id="v-pills-cache" role="tabpanel" aria-labelledby="v-pills-cache-tab">
|
||||||
|
<h3>Cache</h3>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col">URL</th>
|
||||||
|
<th scope="col">Size</th>
|
||||||
|
<th scope="col">Expiration</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{{ range $key, $value := Cache.List }}
|
||||||
|
<tr>
|
||||||
|
<td>{{$key}}</td>
|
||||||
|
<td>{{len $value.Content}}</td>
|
||||||
|
<td>{{UnixTime $value.Expiration true}}</td>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<a href="/api/clear_cache" class="btn btn-danger btn-block">Clear Cache</a>
|
||||||
|
</div>
|
||||||
{{ range .Notifications }}
|
{{ range .Notifications }}
|
||||||
{{$n := .Select}}
|
{{$n := .Select}}
|
||||||
<div class="tab-pane fade" id="v-pills-{{underscore $n.Method}}" role="tabpanel" aria-labelledby="v-pills-{{underscore $n.Method }}-tab">
|
<div class="tab-pane fade" id="v-pills-{{underscore $n.Method}}" role="tabpanel" aria-labelledby="v-pills-{{underscore $n.Method }}-tab">
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// This file was generated by robots at
|
// This file was generated by robots at
|
||||||
// 2019-02-01 11:55:53.781812 -0800 PST m=+0.615412774
|
// 2019-02-01 12:26:35.052075 -0800 PST m=+0.640410556
|
||||||
//
|
//
|
||||||
// This contains the most recently Markdown source for the Statping Wiki.
|
// This contains the most recently Markdown source for the Statping Wiki.
|
||||||
package source
|
package source
|
||||||
|
|
|
@ -247,24 +247,24 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
}
|
}
|
||||||
r := new(http.Request)
|
var req *http.Request
|
||||||
|
if req, err = http.NewRequest(method, url, body); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("User-Agent", "Statping")
|
||||||
|
if content != nil {
|
||||||
|
req.Header.Set("Content-Type", content.(string))
|
||||||
|
}
|
||||||
for _, h := range headers {
|
for _, h := range headers {
|
||||||
keyVal := strings.Split(h, "=")
|
keyVal := strings.Split(h, "=")
|
||||||
if len(keyVal) == 2 {
|
if len(keyVal) == 2 {
|
||||||
if keyVal[0] != "" && keyVal[1] != "" {
|
if keyVal[0] != "" && keyVal[1] != "" {
|
||||||
r.Header.Add(keyVal[0], keyVal[1])
|
req.Header.Set(keyVal[0], keyVal[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if r, err = http.NewRequest(method, url, body); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
r.Header.Set("User-Agent", "Statping")
|
|
||||||
if content != nil {
|
|
||||||
r.Header.Set("Content-Type", content.(string))
|
|
||||||
}
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
if resp, err = client.Do(r); err != nil {
|
if resp, err = client.Do(req); err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.80.42
|
0.80.43
|
||||||
|
|
Loading…
Reference in New Issue