<commit_before>package main

import (
    "fmt"
    "io/ioutil"
)

type Page struct {
    Title string
    Body []byte
}

func main() {
    http.HandleFunc("/show/interfaces", handler)
    http.ListenAndServe(":8081", nil)
}<commit_msg>Added show interfaces to provide json REST API<commit_after>package main

import (
	"fmt"
	//"io/ioutil"
	"encoding/json"
	"github.com/fredhsu/go-eapi"
	"github.com/mitchellh/mapstructure"
	"net/http"
)

type Page struct {
	Title string
	Body  []byte
}

func toJson(i eapi.ShowInterfaces) (s string) {
	b, err := json.Marshal([]eapi.ShowInterfaces{i})
	//b, err = json.Marshal([]string{"hi", "there"})
	if err != nil {
		s = ""
		return
	}
	s = string(b)
	return
}

func myHandler(rw http.ResponseWriter, req *http.Request) {
	cmds := []string{"show interfaces"}
	url := "https://admin:admin@dbrl3-leaf1/command-api/"
	jr := eapi.Call(url, cmds, "json")
	var si eapi.ShowInterfaces
	err := mapstructure.Decode(jr.Result[0], &si)
	if err != nil {
		panic(err)
	}

	rw.Header().Set("Content-Type", "application/json")
	rw.Header().Set("Access-Control-Allow-Origin", "*")
	fmt.Fprint(rw, toJson(si))
	return
}

func main() {
	// Create base path "/v1"
	http.HandleFunc("/show/interfaces", myHandler)
	http.ListenAndServe(":8081", nil)
	// Take in a post with the IP address of the switch
}
{'fraction_non_alphanumeric': 0.170196671709531, 'fraction_numerical': 0.009077155824508321, 'mean_word_length': 3.9365671641791047, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '7405284', 'n_tokens_mistral': 516, 'n_tokens_neox': 502, 'n_words': 112}