<commit_before>package server

import (
	"fmt"
	"html/template"
	"log"
	"net/http"
	"sonet/facebook"
	"sonet/twitter"
	"sonet/utils"
)

type ServerStatus struct {
	Response string
}

type ServerVersion struct {
	Version     string
	Description string
	Environment string
}

func render(w http.ResponseWriter, tmpl string) {
	tmpl = fmt.Sprintf("templates/%s", tmpl)
	t, err := template.ParseFiles(tmpl)
	if err != nil {
		log.Print("template parsing error: ", err)
	}
	err = t.Execute(w, "")
	if err != nil {
		log.Print("template executing error: ", err)
	}
}

func Handler(config utils.Config) http.Handler {
	mux := http.NewServeMux()
	handler := handleJenkinsCall(mux, config)
	return handler
}

func handleJenkinsCall(h http.Handler, config utils.Config) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		fmt.Println("URL: " + req.URL.Path[1:])
		switch req.URL.Path[1:] {
		case "status":
			utils.RespondJson(w, ServerStatus{"OK"})
		case "version":
			utils.RespondJson(w, ServerVersion{config.Version, config.Description, config.Environment})
		case "post":
			switch req.Method {
			case "POST":
				if facebook.CheckLoginStatus() && twitter.CheckLoginStatus() {
					PostRequest("First Multi-Platform Status Posting... YaaY :) ")
				} else {
					fmt.Println("Redirecting to authfb")
				}
			case "GET":
				utils.RespondJson(w, ServerStatus{"End Point Responds"})
			default:
				utils.RespondError(w, nil, http.StatusMethodNotAllowed)
			}
		case "authfb":
			switch req.Method {
			case "POST":
				facebook.Auth(w, req)
			case "GET":
				utils.RespondJson(w, ServerStatus{"End Point Responds"})
			default:
				utils.RespondError(w, nil, http.StatusMethodNotAllowed)
			}
		case "authtwitter":
			switch req.Method {
			case "POST":<commit_msg>Posting STATUS from http post<commit_after>package server

import (
	"fmt"
	"html/template"
	"log"
	"net/http"
	"sonet/facebook"
	"sonet/twitter"
	"sonet/utils"
)

type ServerStatus struct {
	Response string
}

type ServerVersion struct {
	Version     string
	Description string
	Environment string
}

func render(w http.ResponseWriter, tmpl string) {
	tmpl = fmt.Sprintf("templates/%s", tmpl)
	t, err := template.ParseFiles(tmpl)
	if err != nil {
		log.Print("template parsing error: ", err)
	}
	err = t.Execute(w, "")
	if err != nil {
		log.Print("template executing error: ", err)
	}
}

func Handler(config utils.Config) http.Handler {
	mux := http.NewServeMux()
	handler := handleJenkinsCall(mux, config)
	return handler
}

func handleJenkinsCall(h http.Handler, config utils.Config) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		fmt.Println("URL: " + req.URL.Path[1:])
		switch req.URL.Path[1:] {
		case "status":
			utils.RespondJson(w, ServerStatus{"OK"})
		case "version":
			utils.RespondJson(w, ServerVersion{config.Version, config.Description, config.Environment})
		case "post":
			switch req.Method {
			case "POST":
				req.ParseForm()
				status := req.Form.Get("status")
				if status == "" {
					utils.RespondJson(w, ServerStatus{"Please Post along with status Parameter"})
					return
				}
				if facebook.CheckLoginStatus() && twitter.CheckLoginStatus() {
					PostRequest(status)
				} else {
					fmt.Println("Redirecting to authfb")
				}
			case "GET":
				utils.RespondJson(w, ServerStatus{"End Point Responds"})
			default:
				utils.RespondError(w, nil, http.StatusMethodNotAllowed)
			}
		case "authfb":
			switch req.Method {
			case "POST":
				facebook.Auth(w, req)
			case "GET":
				utils.RespondJson(w, ServerStatus{"End Point Responds"})
			default:
				utils.RespondError(w, nil, http.StatusMethodNotAllowed)
			}
		case "authtwitter":
			switch req.Method {
			case "POST":
{'fraction_non_alphanumeric': 0.13540835328544826, 'fraction_numerical': 0.0010641127959563714, 'mean_word_length': 3.915032679738562, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1022210', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1252, 'n_words': 290}