Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/linkedql
- Loading branch information
Showing
67 changed files
with
407 additions
and
2,336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const defaultAddress = "http://localhost:64210/" | ||
|
||
func NewHealthCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "health", | ||
Aliases: []string{}, | ||
Short: "Health check HTTP server", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) > 1 { | ||
return fmt.Errorf("Too many arguments provided, expected 0 or 1") | ||
} | ||
address := defaultAddress | ||
if len(args) == 1 { | ||
address = args[0] | ||
} | ||
healthAddress := address + "health" | ||
resp, err := http.Get(healthAddress) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != 204 { | ||
return fmt.Errorf("/health responded with status code %d, expected 204", resp.StatusCode) | ||
} | ||
log.Printf("%s ok", healthAddress) | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package main | ||
|
||
import ( | ||
"archive/zip" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
const ( | ||
version = "v0.8.0" | ||
fileURL = "https://github.com/cayleygraph/web/releases/download/" + version + "/web.zip" | ||
fileName = "web.zip" | ||
directoryName = "ui" | ||
) | ||
|
||
func main() { | ||
log.Printf("Downloading %s to %s...", fileURL, fileName) | ||
if err := DownloadFile(fileName, fileURL); err != nil { | ||
panic(err) | ||
} | ||
log.Printf("Downloaded %s to %s", fileURL, fileName) | ||
|
||
log.Printf("Extracting %s to %s...", fileName, directoryName) | ||
err := Unzip(fileName, directoryName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
log.Printf("Extracted %s to %s/", fileName, directoryName) | ||
err = os.Remove(fileName) | ||
if err != nil { | ||
panic(err) | ||
} | ||
log.Printf("Removed %s", fileName) | ||
} | ||
|
||
// DownloadFile will download a url to a local file. It's efficient because it will | ||
// write as it downloads and not load the whole file into memory. | ||
func DownloadFile(filepath string, url string) error { | ||
|
||
// Get the data | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != 200 { | ||
return fmt.Errorf("Received %v status code instead of 200 for %v", resp.Status, url) | ||
} | ||
|
||
// Create the file | ||
out, err := os.Create(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
|
||
// Write the body to file | ||
_, err = io.Copy(out, resp.Body) | ||
return err | ||
} | ||
|
||
// Unzip will decompress a zip archive, moving all files and folders | ||
// within the zip file (parameter 1) to an output directory (parameter 2). | ||
func Unzip(src string, dest string) error { | ||
r, err := zip.OpenReader(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer r.Close() | ||
|
||
for _, f := range r.File { | ||
|
||
// Store filename/path for returning and using later on | ||
fpath := filepath.Join(dest, f.Name) | ||
|
||
// Check for ZipSlip. More Info: http://bit.ly/2MsjAWE | ||
if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) { | ||
return fmt.Errorf("%s: illegal file path", fpath) | ||
} | ||
|
||
if f.FileInfo().IsDir() { | ||
// Make Folder | ||
os.MkdirAll(fpath, 0755) | ||
continue | ||
} | ||
|
||
// Make File | ||
if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil { | ||
return err | ||
} | ||
|
||
outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rc, err := f.Open() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = io.Copy(outFile, rc) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Close the file without defer to close before next iteration of loop | ||
err = outFile.Close() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
err = rc.Close() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.