Permalink
Browse files

reformat and rearrange code

  • Loading branch information...
gjerokrsteski committed Oct 19, 2018
1 parent 316fdec commit de5324da7231a10fba83ffcc31d6c357428af17d
Showing with 13 additions and 12 deletions.
  1. +13 −12 main.go
25 main.go
@@ -1,24 +1,25 @@
// Package main is a cli app that implements HTTP service for validating JSON entities by given JSON Schema.
package main

import (
"encoding/json"
"flag"
"fmt"
"github.com/santhosh-tekuri/jsonschema"
"net/http"
"encoding/json"
"os"
"io"
"flag"
"log"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
)

var Version string = "No Version Provided"
var Version = "No Version Provided"
var jsonSchema string
var serviceName string = "HTTP service for validating JSON entities by given JSON Schema"
var serviceName = "HTTP service for validating JSON entities by given JSON Schema"
var servicePort string

//main handles the cli flags and starts an HTTP server by given port.
// main handles the cli flags and starts an HTTP server by given port.
func main() {
flag.StringVar(&servicePort, "port", "6565", "port number to the host")
flag.StringVar(&jsonSchema, "jsonSchema", "./", "absolute path to JSON schema file")
@@ -43,22 +44,22 @@ func main() {
}
}

//handlePing returns a information about running service in the response body as JSON sting.
// handlePing returns a information about running service in the response body as JSON sting.
func handlePing(responseWriter http.ResponseWriter, request *http.Request) {
pingInfo := map[string]string{"service": serviceName, "port": servicePort, "jsonSchemaFile": jsonSchema, "version": Version}
pingInfoMap, _ := json.Marshal(pingInfo)
responseWriter.Header().Set("Content-Type", "application/json")
io.WriteString(responseWriter, string(pingInfoMap))
}

//handleHome returns a BadRequest HTTP status and information as string about how to use the main service.
// handleHome returns a BadRequest HTTP status and information as string about how to use the main service.
func handleHome(responseWriter http.ResponseWriter, request *http.Request) {
responseWriter.WriteHeader(http.StatusBadRequest)
io.WriteString(responseWriter, "Bad Request! Send JSON data at body using route '/validate'\n")
}

//handleValidation responds a StatusUnprocessableEntity if the JSON data is not valid and
//responds StatusOK if JSON data is valid.
// handleValidation responds a StatusUnprocessableEntity if the JSON data is not valid and
// responds StatusOK if JSON data is valid.
func handleValidation(responseWriter http.ResponseWriter, request *http.Request) {
request.ParseForm()

0 comments on commit de5324d

Please sign in to comment.