This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / knotserver / xrpc / version.go
1.2 kB 59 lines
1package xrpc 2 3import ( 4 "fmt" 5 "net/http" 6 "runtime/debug" 7 8 "tangled.org/core/api/tangled" 9 "tangled.org/core/consts" 10) 11 12// version is set during build time. 13var version string 14 15var knotCapabilities = []string{ 16 string(consts.CapKnotACL), 17 string(consts.CapKeepCommit), 18} 19 20func (x *Xrpc) Version(w http.ResponseWriter, r *http.Request) { 21 if version == "" { 22 info, ok := debug.ReadBuildInfo() 23 if !ok { 24 http.Error(w, "failed to read build info", http.StatusInternalServerError) 25 return 26 } 27 28 modVer := info.Main.Version 29 if modVer == "" || modVer == "(devel)" { 30 modVer = "(devel)" 31 } 32 33 var sha string 34 var modified bool 35 for _, setting := range info.Settings { 36 switch setting.Key { 37 case "vcs.revision": 38 sha = setting.Value 39 case "vcs.modified": 40 modified = setting.Value == "true" 41 } 42 } 43 44 if sha == "" { 45 version = modVer 46 } else if modified { 47 version = fmt.Sprintf("%s (%s with modifications)", modVer, sha) 48 } else { 49 version = fmt.Sprintf("%s (%s)", modVer, sha) 50 } 51 } 52 53 response := tangled.KnotVersion_Output{ 54 Version: version, 55 Capabilities: knotCapabilities, 56 } 57 58 x.writeJson(w, response) 59}