Mise en marche de base de /v1/health avec pkg data
Ajouter data/ Ajouter data/ à Dockerfile Ajouter flags pour server.port et server.documents.* Ajouter viper Ajouter example de config à examples/config/ Exécuter serveur sur port custom (8080 par défaut) Retirer copyright notice de main.go Cleanup dependencies (go get, go mod tidy) Ajouter /v1/health Ajouter container minio à docker-compose
This commit is contained in:
parent
4cec29abee
commit
28cc97dcee
8 changed files with 206 additions and 19 deletions
48
data/data.go
Normal file
48
data/data.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
// Package data provides database interactions to the app
|
||||
package data
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Endpoint, AccessKeyID, SecretAccessKey string
|
||||
UseSSL bool
|
||||
MongoClient *minio.Client
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
func NewClient(buckets []string, endpoint, accessKeyID, secretAccessKey string, useSSL bool) (*Client, error) {
|
||||
c := Client{
|
||||
Endpoint: endpoint,
|
||||
AccessKeyID: accessKeyID,
|
||||
SecretAccessKey: secretAccessKey,
|
||||
UseSSL: useSSL,
|
||||
Context: context.Background(),
|
||||
}
|
||||
|
||||
// Initialize minio client object
|
||||
mongo_client, err := minio.New(endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
||||
Secure: useSSL,
|
||||
})
|
||||
if err != nil {
|
||||
return &c, err
|
||||
}
|
||||
|
||||
c.MongoClient = mongo_client
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func (c *Client) BucketExists(bucketName string) (bool, error) {
|
||||
result, err := c.MongoClient.BucketExists(c.Context, bucketName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue