feat (minio): done, upload wip

This commit is contained in:
dpurbosakti
2025-09-24 07:51:15 +07:00
parent 2586bf9b76
commit a50f62f5ec
9 changed files with 446 additions and 0 deletions
@@ -11,6 +11,7 @@ type (
CheckupScopeCode string
AmbulatoryClassCode string
InpatientClassCode string
UploadCode string
)
const (
@@ -64,6 +65,12 @@ const (
ICCICU InpatientClassCode = "icu" // ICU
ICCHCU InpatientClassCode = "hcu" // HCU
ICCVK InpatientClassCode = "vk" // Verlos kamer
UCPRN UploadCode = "person-resident-number" // Person Resident Number
UCPDL UploadCode = "person-driver-license" // Person Driver License
UCPP UploadCode = "person-passport" // Person Passport
UCPFC UploadCode = "person-family-card" // Person Family Card
UCMIR UploadCode = "mcu-item-result" // Mcu Item Result
)
func (ec EncounterClassCode) Code() string {
+104
View File
@@ -0,0 +1,104 @@
package minio
import (
"errors"
"io"
"net/url"
"time"
a "github.com/karincake/apem"
lo "github.com/karincake/apem/loggero"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
var O MinioCfg = MinioCfg{}
var I *minio.Client
type MinioCfg struct {
Endpoint string
Region string
AccessKey string `yaml:"accessKey"`
SecretKey string `yaml:"secretKey"`
UseSsl bool `yaml:"useSsl"`
BucketName []string `yaml:"bucketName"`
}
type UploadReaderInput struct {
File io.Reader
Name string
Size int64
ContentType string
BucketName string
}
type UploadPathInput struct {
BucketName string
ContentType string
Name string
Path string
}
type PresignedGetInput struct {
Bucket string
Object string
Expiry time.Duration
ReqParams url.Values
}
type ResponsePostPolicy struct {
Url string `json:"url"`
FormData map[string]string `json:"form-data"`
}
func (c MinioCfg) GetRegion() string {
return c.Region
}
func (c MinioCfg) GetEndpoint() string {
return c.Endpoint
}
func (c MinioCfg) GetUseSsl() bool {
return c.UseSsl
}
func (c MinioCfg) GetBucketName() []string {
return c.BucketName
}
// connect db
func Connect() {
a.ParseSingleCfg(&O)
NewClient(&O)
if I == nil {
panic("minio client is nil")
}
lo.I.Println("Instantiation for object storage service using Minio, status: DONE!!")
}
func NewClient(cfg *MinioCfg) error {
// Initialize minio client object.
endpoint := cfg.Endpoint
if endpoint == "" {
return errors.New("config minio endpoint empty")
}
accessKey := cfg.AccessKey
if accessKey == "" {
return errors.New("config minio access key empty")
}
secretKey := cfg.SecretKey
if secretKey == "" {
return errors.New("config minio secret key empty")
}
useSSL := cfg.UseSsl
minioClient, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKey, secretKey, ""),
Secure: useSSL,
})
if err != nil {
return err
}
I = minioClient
return nil
}
@@ -43,6 +43,7 @@ import (
/******************** infra ********************/
gs "simrs-vx/internal/infra/gorm-setting"
minio "simrs-vx/internal/infra/minio"
ssdb "simrs-vx/internal/infra/ss-db"
/******************** pkg ********************/
@@ -50,6 +51,7 @@ import (
hc "simrs-vx/pkg/handler-crud-helper"
lh "simrs-vx/pkg/lang-helper"
handlerlogger "simrs-vx/pkg/middleware/handler-logger"
mh "simrs-vx/pkg/minio-helper"
zlc "simrs-vx/pkg/zerolog-ctx"
/******************** sources ********************/
@@ -97,6 +99,8 @@ func SetRoutes() http.Handler {
a.RegisterExtCall(zlc.Adjust)
a.RegisterExtCall(ssdb.SetInstance)
a.RegisterExtCall(lh.Populate)
a.RegisterExtCall(minio.Connect)
a.RegisterExtCall(mh.I.SetClient)
a.RegisterExtCall(validation.RegisterValidation)
r := http.NewServeMux()
@@ -0,0 +1,56 @@
package upload
// "net/http"
// uh "simrs-vx/pkg/upload-helper"
// uploadHandler handles single file upload requests
// func uploadHandler(w http.ResponseWriter, r *http.Request) {
// if r.Method == "OPTIONS" {
// w.WriteHeader(http.StatusNoContent)
// return
// }
// if r.Method != "POST" {
// writeJSONResponse(w, http.StatusMethodNotAllowed, uh.UploadResponse{
// Success: false,
// Message: "Method not allowed. Use POST.",
// })
// return
// }
// // Parse multipart form (32MB max memory)
// err := r.ParseMultipartForm(32 << 20)
// if err != nil {
// writeJSONResponse(w, http.StatusBadRequest, uh.UploadResponse{
// Success: false,
// Message: "Failed to parse multipart form",
// })
// return
// }
// // Get file from form
// file, header, err := r.FormFile("file")
// if err != nil {
// writeJSONResponse(w, http.StatusBadRequest, uh.UploadResponse{
// Success: false,
// Message: "No file uploaded or invalid file field name. Use 'file' as field name.",
// })
// return
// }
// defer file.Close()
// // Upload file
// response, err := service.UploadFile(file, header.Filename, header.Size)
// if err != nil {
// writeJSONResponse(w, http.StatusInternalServerError, *response)
// return
// }
// if response.Success {
// writeJSONResponse(w, http.StatusOK, *response)
// } else {
// writeJSONResponse(w, http.StatusBadRequest, *response)
// }
// }