1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pasteapi.go/client_get.go

46 lines
1.3 KiB

// Copyright 2022 Leonid Maslakov. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package pasteapi
import (
"encoding/json"
"net/http"
"strconv"
)
// Get gets the paste from the server by its ID.
//
// 1. If the "openOneUse" parameter is set to "true" and the paste is intended for a single use,
// the function will return the entire paste, and the paste will be deleted from the server.
//
// 2. If the "openOneUse" parameter is set to "false" and the paste is intended for a single use,
// the function will return only the "ID" and "OneUse" fields and the paste will NOT be deleted from the server.
//
// 3. If the paste is not destroyed after reading the "openOneUse" parameter does not affect anything.
func (server Server) Get(id string, openOneUse bool) (Paste, error) {
var paste Paste
// Make GET request
resp, err := http.Get(server.Server + "/api/v1/get?id=" + id + "&openOneUse=" + strconv.FormatBool(openOneUse))
if err != nil {
return paste, err
}
defer resp.Body.Close()
// Check HTTP response code
err = checkStatus(resp)
if err != nil {
return paste, err
}
// Parse answer
err = json.NewDecoder(resp.Body).Decode(&paste)
if err != nil {
return paste, err
}
return paste, nil
}