提交 f1f9726a 编写于 作者: T Taras Madan

dashboard/app: prepare json generation code for extension

上级 d521bc56
......@@ -5,7 +5,6 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"net/http"
......@@ -1024,11 +1023,8 @@ func isJSONRequested(request *http.Request) bool {
return request.FormValue("json") == "1"
}
func writeJSONVersionOf(writer http.ResponseWriter, bugPage *uiBugPage) error {
data, err := json.MarshalIndent(
GetExtAPIDescrForBugPage(bugPage),
"",
"\t")
func writeJSONVersionOf(writer http.ResponseWriter, page interface{}) error {
data, err := GetJSONDescrFor(page)
if err != nil {
return err
}
......
......@@ -3,17 +3,19 @@
package main
import "encoding/json"
// publicApiBugDescription is used to serve the /bug HTTP requests
// and provide JSON description of the BUG. Backward compatible.
type PublicAPIBugDescription struct {
type publicAPIBugDescription struct {
Version int `json:"version"`
Title string `json:"title,omitempty"`
// links to the discussions
Discussions []string `json:"discussions,omitempty"`
Crashes []PublicAPICrashDescription `json:"crashes,omitempty"`
Crashes []publicAPICrashDescription `json:"crashes,omitempty"`
}
type PublicAPICrashDescription struct {
type publicAPICrashDescription struct {
SyzReproducer string `json:"syz-reproducer,omitempty"`
CReproducer string `json:"c-reproducer,omitempty"`
KernelConfig string `json:"kernel-config,omitempty"`
......@@ -25,9 +27,9 @@ type PublicAPICrashDescription struct {
Architecture string `json:"architecture,omitempty"`
}
func GetExtAPIDescrForBugPage(bugPage *uiBugPage) *PublicAPIBugDescription {
func getExtAPIDescrForBugPage(bugPage *uiBugPage) *publicAPIBugDescription {
crash := bugPage.Crashes.Crashes[0]
return &PublicAPIBugDescription{
return &publicAPIBugDescription{
Version: 1,
Title: bugPage.Bug.Title,
Discussions: func() []string {
......@@ -36,7 +38,7 @@ func GetExtAPIDescrForBugPage(bugPage *uiBugPage) *PublicAPIBugDescription {
}
return []string{bugPage.Bug.ExternalLink}
}(),
Crashes: []PublicAPICrashDescription{{
Crashes: []publicAPICrashDescription{{
SyzReproducer: crash.ReproSyzLink,
CReproducer: crash.ReproCLink,
KernelConfig: crash.KernelConfigLink,
......@@ -49,3 +51,14 @@ func GetExtAPIDescrForBugPage(bugPage *uiBugPage) *PublicAPIBugDescription {
}},
}
}
func GetJSONDescrFor(page interface{}) ([]byte, error) {
var res interface{}
switch i := page.(type) {
case *uiBugPage:
res = getExtAPIDescrForBugPage(i)
default:
return nil, ErrClientNotFound
}
return json.MarshalIndent(res, "", "\t")
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册