@ -15,18 +15,21 @@ var (
)
func MinioInit ( ) {
log . NewInfo ( "" , utils . GetSelfFuncName ( ) )
operationID := utils . OperationIDGenerator ( )
log . NewInfo ( operationID , utils . GetSelfFuncName ( ) , "minio config: " , config . Config . Credential . Minio )
minioUrl , err := url2 . Parse ( config . Config . Credential . Minio . Endpoint )
if err != nil {
log . NewError ( "" , utils . GetSelfFuncName ( ) , "parse failed, please check config/config.yaml" , err . Error ( ) )
log . NewError ( operationID , utils . GetSelfFuncName ( ) , "parse failed, please check config/config.yaml" , err . Error ( ) )
return
}
log . NewInfo ( operationID , utils . GetSelfFuncName ( ) , "Parse ok " , config . Config . Credential . Minio )
minioClient , err = minio . New ( minioUrl . Host , & minio . Options {
Creds : credentials . NewStaticV4 ( config . Config . Credential . Minio . AccessKeyID , config . Config . Credential . Minio . SecretAccessKey , "" ) ,
Secure : false ,
} )
log . NewInfo ( operationID , utils . GetSelfFuncName ( ) , "new ok " , config . Config . Credential . Minio )
if err != nil {
log . NewError ( "" , utils . GetSelfFuncName ( ) , "init minio client failed" , err . Error ( ) )
log . NewError ( operationID , utils . GetSelfFuncName ( ) , "init minio client failed" , err . Error ( ) )
return
}
opt := minio . MakeBucketOptions {
@ -35,15 +38,15 @@ func MinioInit() {
}
err = minioClient . MakeBucket ( context . Background ( ) , config . Config . Credential . Minio . Bucket , opt )
if err != nil {
log . New Info( "" , utils . GetSelfFuncName ( ) , err . Error ( ) )
log . New Error( operationID , utils . GetSelfFuncName ( ) , "MakeBucket failed " , err . Error ( ) )
exists , err := minioClient . BucketExists ( context . Background ( ) , config . Config . Credential . Minio . Bucket )
if err == nil && exists {
log . New Info( "" , utils . GetSelfFuncName ( ) , "We already own %s\n ", config . Config . Credential . Minio . Bucket )
log . New Warn( operationID , utils . GetSelfFuncName ( ) , "We already own ", config . Config . Credential . Minio . Bucket )
} else {
if err != nil {
log . NewError ( "" , utils . GetSelfFuncName ( ) , err . Error ( ) )
log . NewError ( operationID , utils . GetSelfFuncName ( ) , err . Error ( ) )
}
log . NewError ( "" , utils . GetSelfFuncName ( ) , "create bucket failed and bucket not exists" )
log . NewError ( operationID , utils . GetSelfFuncName ( ) , "create bucket failed and bucket not exists" )
return
}
}
@ -53,5 +56,5 @@ func MinioInit() {
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in web", err.Error())
// return
//}
log . NewInfo ( "" , utils . GetSelfFuncName ( ) , "minio create and set policy success" )
log . NewInfo ( operationID , utils . GetSelfFuncName ( ) , "minio create and set policy success" )
}