<commit_before>package main

import (
    "fmt"
    "github.com/cailei/gopm_index/gopm_index"
    "io"
    "io/ioutil"
    "log"
    "net/http"
    "net/url"
    "strconv"
)

var remote_db_host string = "http://localhost:8080"

func agent_get_full_index_reader() io.ReadCloser {
    request := remote_db_host + "/all"
    return _get_body_reader(request)
}

func agent_package_name_exists(name string) bool {
    request := fmt.Sprintf("%v/name_exists?name=%v", remote_db_host, name)
    content := _get_body_content(request)
    exists, err := strconv.ParseBool(content)
    if err != nil {
        log.Fatalln(err)
    }
    return exists
}

func agent_upload_package(meta gopm_index.PackageMeta) {
    request := fmt.Sprintf("%v/publish", remote_db_host)

    // marshal PackageMeta to json
    json, err := meta.ToJson()
    if err != nil {
        log.Fatalln(err)
    }

    // create a POST request
    response, err := http.PostForm(request, url.Values{"pkg": {string(json)}})
    if err != nil {
        log.Fatalln(err)
    }

    // check response
    if response.StatusCode != 200 {
        log.Fatalln(response.Status)
    }

    body, err := ioutil.ReadAll(response.Body)
    defer response.Body.Close()
    if err != nil {
        log.Fatalln(err)
    }

    succ, err := strconv.ParseBool(string(body))
    if err != nil {
        log.Fatalln(err)
    }

    if !succ {
        log.Fatalln("Unknown error!")
    }
}

func _get_body_reader(request string) io.ReadCloser {
    // GET the index content
    response, err := http.Get(request)
    if err != nil {
        log.Fatalln(err)
    }

    // check response
    if response.StatusCode != 200 {
        log.Fatalln(response.Status)<commit_msg>print server returned message<commit_after>package main

import (
    "fmt"
    "github.com/cailei/gopm_index/gopm_index"
    "io"
    "io/ioutil"
    "log"
    "net/http"
    "net/url"
    "strconv"
)

var remote_db_host string = "http://localhost:8080"

func agent_get_full_index_reader() io.ReadCloser {
    request := remote_db_host + "/all"
    return _get_body_reader(request)
}

func agent_package_name_exists(name string) bool {
    request := fmt.Sprintf("%v/name_exists?name=%v", remote_db_host, name)
    content := _get_body_content(request)
    exists, err := strconv.ParseBool(content)
    if err != nil {
        log.Fatalln(err)
    }
    return exists
}

func agent_upload_package(meta gopm_index.PackageMeta) {
    request := fmt.Sprintf("%v/publish", remote_db_host)

    // marshal PackageMeta to json
    json, err := meta.ToJson()
    if err != nil {
        log.Fatalln(err)
    }

    // create a POST request
    response, err := http.PostForm(request, url.Values{"pkg": {string(json)}})
    if err != nil {
        log.Fatalln(err)
    }

    body, err := ioutil.ReadAll(response.Body)
    defer response.Body.Close()
    if err != nil {
        log.Fatalln(err)
    }

    if len(body) > 0 {
        fmt.Println(string(body))
    }

    // check response
    if response.StatusCode != 200 {
        log.Fatalln(response.Status)
    }
}

func _get_body_reader(request string) io.ReadCloser {
    // GET the index content
    response, err := http.Get(request)
    if err != nil {
        log.Fatalln(err)
    }

    // check response
    if response.StatusCode != 200 {
        log.Fatalln(response.Status)
{'fraction_non_alphanumeric': 0.12795216741405083, 'fraction_numerical': 0.006278026905829596, 'mean_word_length': 2.6251354279523293, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, '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': '3251180', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1151, 'n_words': 233}