Merge branch 'master' into daniel/continuservconcurrency
Conflicts: scripts/continuserv/main.go
This commit is contained in:
commit
c3608b3a69
7 changed files with 250 additions and 7 deletions
|
@ -116,8 +116,14 @@ func serve(w http.ResponseWriter, req *http.Request) {
|
|||
wgMu.Lock()
|
||||
wg.Wait()
|
||||
wgMu.Unlock()
|
||||
b := toServe.Load().([]byte)
|
||||
w.Write(b)
|
||||
b := toServe.Load().(bytesOrErr)
|
||||
if b.err != nil {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte(b.err.Error()))
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(b.bytes))
|
||||
}
|
||||
}
|
||||
|
||||
func populateOnce(dir string) {
|
||||
|
@ -130,15 +136,15 @@ func populateOnce(dir string) {
|
|||
cmd.Stderr = &b
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
toServe.Store([]byte(fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String()).Error()))
|
||||
toServe.Store(bytesOrErr{nil, fmt.Errorf("error generating spec: %v\nOutput from gendoc:\n%v", err, b.String())})
|
||||
return
|
||||
}
|
||||
specBytes, err := ioutil.ReadFile(path.Join(dir, "scripts", "gen", "specification.html"))
|
||||
if err != nil {
|
||||
toServe.Store([]byte(fmt.Errorf("error reading spec: %v", err).Error()))
|
||||
toServe.Store(bytesOrErr{nil, fmt.Errorf("error reading spec: %v", err)})
|
||||
return
|
||||
}
|
||||
toServe.Store(specBytes)
|
||||
toServe.Store(bytesOrErr{specBytes, nil})
|
||||
}
|
||||
|
||||
func doPopulate(ch chan struct{}, dir string) {
|
||||
|
@ -165,3 +171,8 @@ func exists(path string) bool {
|
|||
_, err := os.Stat(path)
|
||||
return !os.IsNotExist(err)
|
||||
}
|
||||
|
||||
type bytesOrErr struct {
|
||||
bytes []byte
|
||||
err error
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue