Esempio n. 1
0
File: agent.go Progetto: cailei/gopm
func (agent *Agent) uploadPackage(meta 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)
	}
}
Esempio n. 2
0
func (db *LocalDB) readPackage() (pkg *index.PackageMeta, err error) {
	pkg = nil

	line, err := db.readLine()
	if err != nil {
		return
	}

	// construct a PackageMeta from the line
	var meta index.PackageMeta
	err = meta.FromJson([]byte(line))
	if err != nil {
		return
	}

	pkg = &meta
	err = nil
	return
}