merge: apiclient dans api.go
This commit is contained in:
parent
103745fe76
commit
9209663593
1 changed files with 7 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
package api
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -10,9 +10,6 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"codeberg.org/vlbeaudoin/voki/v3"
|
"codeberg.org/vlbeaudoin/voki/v3"
|
||||||
"git.agecem.com/agecem/agecem-org/apirequest"
|
|
||||||
"git.agecem.com/agecem/agecem-org/apiresponse"
|
|
||||||
"git.agecem.com/agecem/agecem-org/config"
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +21,7 @@ type API struct {
|
||||||
// provided the configuration options are managed by
|
// provided the configuration options are managed by
|
||||||
// https://git.agecem.com/agecem/agecem-org/config
|
// https://git.agecem.com/agecem/agecem-org/config
|
||||||
func NewFromViper(client *http.Client) (api *API, err error) {
|
func NewFromViper(client *http.Client) (api *API, err error) {
|
||||||
var config config.Config
|
var config Config
|
||||||
if err = viper.Unmarshal(&config); err != nil {
|
if err = viper.Unmarshal(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -36,7 +33,7 @@ func New(client *http.Client, host, key string, port int, protocol string) (*API
|
||||||
return &API{Voki: voki.New(client, host, key, port, protocol)}, nil
|
return &API{Voki: voki.New(client, host, key, port, protocol)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) UploadDocuments(bucketName string, fileHeaders ...*multipart.FileHeader) (response apiresponse.V1DocumentsPOST, err error) {
|
func (a *API) UploadDocuments(bucketName string, fileHeaders ...*multipart.FileHeader) (response CreateDocumentsResponse, err error) {
|
||||||
if count := len(fileHeaders); count == 0 {
|
if count := len(fileHeaders); count == 0 {
|
||||||
err = fmt.Errorf("api.(*API).UploadDocuments requiert au moins 1 fichier")
|
err = fmt.Errorf("api.(*API).UploadDocuments requiert au moins 1 fichier")
|
||||||
return
|
return
|
||||||
|
@ -110,8 +107,7 @@ func (a *API) UploadDocuments(bucketName string, fileHeaders ...*multipart.FileH
|
||||||
return response, json.NewDecoder(httpResponse.Body).Decode(&response)
|
return response, json.NewDecoder(httpResponse.Body).Decode(&response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (apiresponse.V1DocumentPOST, error) {
|
func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (response CreateDocumentResponse, err error) {
|
||||||
var response apiresponse.V1DocumentPOST
|
|
||||||
endpoint := fmt.Sprintf("%s://%s:%d",
|
endpoint := fmt.Sprintf("%s://%s:%d",
|
||||||
a.Voki.Protocol,
|
a.Voki.Protocol,
|
||||||
a.Voki.Host,
|
a.Voki.Host,
|
||||||
|
@ -175,12 +171,12 @@ func (a *API) UploadDocument(bucket string, file_header *multipart.FileHeader) (
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ListBuckets() (response apiresponse.V1BucketsGET, err error) {
|
func (a *API) ListBuckets() (response ListBucketsResponse, err error) {
|
||||||
return response, a.Voki.Unmarshal(http.MethodGet, "/v1/bucket", nil, true, &response)
|
return response, a.Voki.Unmarshal(http.MethodGet, "/v1/bucket", nil, true, &response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) Seed() (response apiresponse.V1SeedPOST, err error) {
|
func (a *API) Seed() (response ExecuteSeedResponse, err error) {
|
||||||
request, err := apirequest.NewV1SeedPOST()
|
request, err := NewV1SeedPOST()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
Loading…
Reference in a new issue