Skip to content

Commit

Permalink
cli/api: 1.1.0 changes; / -> /health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
program-- committed May 28, 2024
1 parent f5264a1 commit 5662c87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions api/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
# <https://www.gnu.org/licenses/>.

#* @apiTitle Hydrofabric Subsetter
#* @apiDescription This is a sample server for a subsetting Cloud Native Hydrofabrics
#* @apiDescription This is a REST API for subsetting cloud-native hydrofabrics.
#* @apiContact list(name = "hfsubsetCLI API Support", email = "[email protected]")
#* @apiLicense list(name = "GNU General Public License (GPL-3.0)", url = "https://www.gnu.org/licenses/")
#* @apiVersion 1.1.0

logger::log_formatter(logger::formatter_glue_safe)

Expand Down Expand Up @@ -149,9 +150,9 @@ function(req) {
}

#* Health Check
#* @head /
#* @head /health
function(req, res) {
res$setHeader("X-HFSUBSET-API-VERSION", "1.0.0")
res$setHeader("X-HFSUBSET-API-VERSION", "1.1.0")
res
}

Expand Down
11 changes: 9 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const USAGE string = `hfsubset - Hydrofabric Subsetter
Usage:
hfsubset [OPTIONS] identifiers...
hfsubset (-h | --help)
hfsubset -version
Examples:
hfsubset -o ./divides_nexus.gpkg \
Expand Down Expand Up @@ -154,7 +155,7 @@ func outputFile(path string, r io.Reader) (int64, error) {
}

func endpointVerify(endpoint string) (string, error) {
resp, err := sendRequest("HEAD", endpoint)
resp, err := sendRequest("HEAD", endpoint+"health")
if err != nil {
return "", err
}
Expand All @@ -167,7 +168,7 @@ func endpointVerify(endpoint string) (string, error) {

ver := resp.Header.Get("X-HFSUBSET-API-VERSION")
if ver == "" {
ver = "0.1.0-alpha" // initial version, pre 0.1.0
ver = "<=1.0.0" // initial version, pre 0.1.0
}

return ver, nil
Expand Down Expand Up @@ -216,10 +217,16 @@ func main() {
flag.BoolVar(&debug, "debug", false, "Run in debug mode")
flag.BoolVar(&verify, "verify", true, "Verify that endpoint is available")
flag.BoolVar(&dryRun, "dryrun", false, "Perform a dry run, only outputting the request that will be sent")
version := flag.Bool("version", false, "Output the version")
layers := flag.String("l", "divides,flowlines,network,nexus", "Comma-delimited list of layers to subset.")
weights := flag.String("w", "", "Comma-delimited list of weights to generate over the subset.")
flag.Parse()

if version != nil && *version {
fmt.Println("hfsubset v1.1.0")
return
}

if len(flag.Args()) == 0 {
flag.Usage()
return
Expand Down

0 comments on commit 5662c87

Please sign in to comment.