Commit c57b1675c67129986de7f0b377a9471ba1bd4ba2

Authored by Georg Hopp
1 parent 71b69fcd

Add first main.go ...

Showing 1 changed file with 75 additions and 0 deletions
  1 +/*
  2 +This is some stuff...
  3 +
  4 +Authors:
  5 +Georg Hopp <georg@steffers.org>
  6 +
  7 +Changes:
  8 +2018-09-30 [Georg Hopp] File created.
  9 +
  10 +Copyright © 2018 Georg Hopp
  11 +
  12 +This program is free software: you can redistribute it and/or modify
  13 +it under the terms of the GNU General Public License as published by
  14 +the Free Software Foundation, either version 3 of the License, or
  15 +(at your option) any later version.
  16 +
  17 +This program is distributed in the hope that it will be useful,
  18 +but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20 +GNU General Public License for more details.
  21 +
  22 +You should have received a copy of the GNU General Public License
  23 +along with this program. If not, see <http://www.gnu.org/licenses/>.
  24 +*/
  25 +package test
  26 +
  27 +import (
  28 + "encoding/json"
  29 + "net/http"
  30 + "strings"
  31 + "os"
  32 + "io"
  33 +)
  34 +
  35 +type ApiHandler struct {}
  36 +
  37 +type version struct {
  38 + Version string `json:"Version"`
  39 + BuildCommit string `json:"BuildCommint"`
  40 + BuildTime string `json:"BuildTimestamp"`
  41 +}
  42 +
  43 +func (handler *ApiHandler) ServeHTTP(
  44 + response ResponseWriter,
  45 + request *Request,
  46 +) {
  47 + dirs := strings.split(request.URL.Path, "/")
  48 + switch dirs[0] {
  49 + case "version":
  50 + v, err := json.Marshal(
  51 + version{
  52 + VERSION,
  53 + REVISION,
  54 + BUILD_TIME,
  55 + },
  56 + )
  57 + if err != nil {
  58 + http.Error(w, "Unable to encode version information", 500)
  59 + return
  60 + }
  61 + io.WriteString(w, string(v[:]))
  62 + default:
  63 + http.NotFound(w, req)
  64 + return
  65 + }
  66 +}
  67 +
  68 +func router() {
  69 + http.HandleFunc(
  70 + "/api/0.0.1/",
  71 + http.StripPrefix("/api/0.0.1/", ApiHandler{}),
  72 + )
  73 +}
  74 +
  75 +// vim: ts=4 sts=4 sw=4 noet tw=72:
... ...
Please register or login to post a comment