backend for xcvr appview
2
fork

Configure Feed

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

add initial lexicon and endpoints for them

+60 -56
+22
lexicons/getChannels
··· 1 + { 2 + "lexicon": 1, 3 + "id": "org.xcvr.getChannels", 4 + "defs": { 5 + "main": { 6 + "type": "query", 7 + "output": { 8 + "encoding": "application/json", 9 + "schema": { 10 + "type": "array", 11 + "items": { 12 + "type": "object", 13 + "properties": { 14 + "band": { "type": "string", "maxLength": 256}, 15 + "sign": { "type": "string", "maxLength": 64} 16 + } 17 + } 18 + } 19 + } 20 + } 21 + } 22 + }
+17
lexicons/initChannel.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "org.xcvr.initChannel", 4 + "defs": { 5 + "main": { 6 + "type": "procedure", 7 + "parameters": { 8 + "type": "params", 9 + "required": ["band"], 10 + "properties": { 11 + "band": { "type": "string", "maxLength": 256}, 12 + "sign": { "type": "string", "maxLength": 64} 13 + } 14 + } 15 + } 16 + } 17 + }
+21 -56
server/cmd/main.go
··· 1 1 package main 2 2 3 3 import ( 4 + "encoding/json" 4 5 "fmt" 5 6 "net/http" 6 7 ··· 9 10 10 11 var ( 11 12 channelToServer map[string]*lrcd.Server 13 + channels []channel 12 14 ) 13 15 14 16 func main() { 15 - channelToServer = make( map[string]*lrcd.Server) 17 + channelToServer = make(map[string]*lrcd.Server) 16 18 fmt.Println("hello world") 17 - http.HandleFunc("GET /", homeHandler) 19 + http.HandleFunc("GET /xrpc/getChannels", getChannels) 18 20 19 - http.HandleFunc("GET /{channel}", serverStart) 21 + http.HandleFunc("POST /xrpc/initChannel", initChannel) 20 22 http.ListenAndServe(":8080", nil) 21 23 } 22 24 23 - func serverStart(w http.ResponseWriter, r *http.Request) { 24 - name := r.PathValue("channel") 25 - fmt.Fprintln(w,name) 26 - _, ok := channelToServer[name] 27 - if ok { 28 - fmt.Fprint(w, "already created server") 29 - return 25 + func getChannels(w http.ResponseWriter, r *http.Request) { 26 + encoder := json.NewEncoder(w) 27 + err := encoder.Encode(channels) 28 + if err != nil { 29 + panic(err) 30 30 } 31 - channelToServer[name] = nil 32 - fmt.Fprintln(w, "created server") 33 - // if server != nil { 34 - // fmt.Fprint(w, "server already started") 35 - // return 36 - // } 37 - // var err error 38 - // server, err = lrcd.NewServer(lrcd.WithWSPort(8080), lrcd.WithLogging(os.Stdout, true)) 39 - // if err != nil { 40 - // fmt.Println(err.Error()) 41 - // fmt.Fprintln(w, "failed to start") 42 - // return 43 - // } 44 - // err = server.Start() 45 - // if err != nil { 46 - // fmt.Println(err.Error()) 47 - // fmt.Fprintln(w, "failed to start") 48 - // return 49 - // } 50 - // fmt.Fprintln(w, "started") 51 31 } 52 32 53 - func serverStop(w http.ResponseWriter, r *http.Request) { 54 - // if server == nil { 55 - // fmt.Fprintln(w, "no server to stop") 56 - // return 57 - // } 58 - // err := server.Stop() 59 - // if err != nil { 60 - // fmt.Println(err.Error()) 61 - // fmt.Fprintln(w, "failed to stop") 62 - // return 63 - // } 64 - // server = nil 65 - // fmt.Fprintln(w, "stopped") 33 + type channel struct { 34 + Band string `json:"band"` 35 + Sign string `json:"sign"` 66 36 } 67 37 68 - func homeHandler(w http.ResponseWriter, r *http.Request) { 69 - fmt.Fprintln(w, "welcome") 70 - for k, _ := range channelToServer { 71 - fmt.Fprintln(w, k) 38 + func initChannel(w http.ResponseWriter, r *http.Request) { 39 + decoder := json.NewDecoder(r.Body) 40 + var c channel 41 + err := decoder.Decode(&c) 42 + if err != nil { 43 + panic(err) 72 44 } 45 + channels = append(channels, c) 46 + fmt.Printf("created a channel on band: %s and call sign: %s\n", c.Band, c.Sign) 73 47 } 74 - 75 - 76 - 77 - 78 - 79 - 80 - 81 - 82 - 83 48 84 49 85 50