Skip to content
Snippets Groups Projects
Commit 39345b8e authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

start to set up HandlerComiits

parent 7acefc61
No related branches found
No related tags found
No related merge requests found
......@@ -17,10 +17,10 @@ func main() {
http.HandleFunc("/", assignment2.HandlerNil)
http.HandleFunc("/repocheck/v1/commits", assignment2.HandlerCommits) // runs handelr function
http.HandleFunc("/repocheck/v1/languages", assignment2.HandlerLanguages) // runs handelr function
http.HandleFunc("/repocheck/v1/issues", assignment2.HandlerIssues) // runs handelr function
http.HandleFunc("/repocheck/v1/status", assignment2.HandlerStatus) // runs handelr function
http.HandleFunc("/repocheck/v1/webhooks", assignment2.HandlerWebhooks) // runs handelr function
// http.HandleFunc("/repocheck/v1/languages", assignment2.HandlerLanguages) // runs handelr function
// http.HandleFunc("/repocheck/v1/issues", assignment2.HandlerIssues) // runs handelr function
// http.HandleFunc("/repocheck/v1/status", assignment2.HandlerStatus) // runs handelr function
// http.HandleFunc("/repocheck/v1/webhooks", assignment2.HandlerWebhooks) // runs handelr function
fmt.Println("Listening on port " + port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
package assignment2
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
)
func HandlerNil(w http.ResponseWriter, r *http.Request) { //standar default respons
......@@ -20,36 +23,84 @@ func QueryGet(s string, t string, r *http.Request) string {
}
func HandlerCommits(w http.ResponseWriter, r *http.Request) {
func DoRequest(Client *http.Client, w http.ResponseWriter, API string) *http.Response { // Request api
req, err := http.NewRequest(http.MethodGet, API, nil)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
panic(err)
}
limit := QueryGet("limit", "5", r)
resp, err := Client.Do(req)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
panic(err)
}
auth := QueryGet("auth", "false", r)
return resp
}
func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
func HandlerCommits(w http.ResponseWriter, r *http.Request) {
limit := QueryGet("limit", "5", r)
var I []IDS
var C []Commits
auth := QueryGet("auth", "false", r)
APIURL := "https://git.gvk.idi.ntnu.no/api/v4/project"
Client := http.DefaultClient
}
// limit := QueryGet("limit", "5", r)
// auth := QueryGet("auth", "false", r)
func HandlerIssues(w http.ResponseWriter, r *http.Request) {
resp := DoRequest(Client, w, APIURL)
types := r.URL.Query().Get("type")
if types == "" {
// error
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
auth := QueryGet("auth", "false", r)
json.Unmarshal([]byte(data), &I)
}
var URL string
for _, i := range I {
URL = APIURL + "/" + strconv.Itoa(i.ID) + "/repository/commits"
func HandlerStatus(w http.ResponseWriter, r *http.Request) {
resp = DoRequest(Client, w, URL)
data, err = ioutil.ReadAll(resp.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
func HandlerWebhooks(w http.ResponseWriter, r *http.Request) {
json.Unmarshal([]byte(data), &C)
}
}
// func HandlerLanguages(w http.ResponseWriter, r *http.Request) {
// limit := QueryGet("limit", "5", r)
// auth := QueryGet("auth", "false", r)
// }
// func HandlerIssues(w http.ResponseWriter, r *http.Request) {
// types := r.URL.Query().Get("type")
// if types == "" {
// // error
// }
// auth := QueryGet("auth", "false", r)
// }
// func HandlerStatus(w http.ResponseWriter, r *http.Request) {
// }
// func HandlerWebhooks(w http.ResponseWriter, r *http.Request) {
// }
......@@ -2,6 +2,10 @@ package assignment2
//************* Commits ******************
type IDS struct {
ID int `json:"id"`
}
type RepoAndCommit struct {
Repository string `json:"repository"`
Commits int `json:"commits"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment