aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2018-09-30 13:31:27 -0700
committerChristine Dodrill <me@christine.website>2018-09-30 13:31:27 -0700
commitb1af575815bdcc05329f3aa92bcaa46b6fb0ada6 (patch)
treea8f35266af6a81161cf3f05e2b3fd914b301ab3a /internal
parent9aff773cf65fef8ae2ca1bd0466c6d54819b0d69 (diff)
downloadx-b1af575815bdcc05329f3aa92bcaa46b6fb0ada6.tar.xz
x-b1af575815bdcc05329f3aa92bcaa46b6fb0ada6.zip
internal: add license flag
Diffstat (limited to 'internal')
-rw-r--r--internal/internal.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/internal.go b/internal/internal.go
new file mode 100644
index 0000000..f21624e
--- /dev/null
+++ b/internal/internal.go
@@ -0,0 +1,40 @@
+package internal
+
+import (
+ "encoding/json"
+ "flag"
+ "fmt"
+ "log"
+ "net/http"
+ "os"
+
+ "github.com/Xe/x/tools/license/licenses"
+ "go4.org/legal"
+)
+
+var (
+ licenseShow = flag.Bool("license", false, "show software license?")
+)
+
+func init() {
+ legal.RegisterLicense(licenses.CC0License)
+ legal.RegisterLicense(licenses.SQLiteBlessing)
+
+ http.HandleFunc("/.within/licenses", func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(legal.Licenses())
+ })
+}
+
+// HandleLicense optionally shows all software licenses.
+func HandleLicense() {
+ if *licenseShow {
+ log.Printf("Licenses for %v", os.Args)
+
+ for _, li := range legal.Licenses() {
+ fmt.Println(li)
+ fmt.Println()
+ }
+
+ os.Exit(0)
+ }
+}