Skip to content

Commit 326220b

Browse files
kplgrcloudlena
authored andcommitted
Initial gofmt run
1 parent b5823dd commit 326220b

File tree

4 files changed

+66
-66
lines changed

4 files changed

+66
-66
lines changed

internal/app/s3manager/instance_handlers.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ func HandleGetS3Instances(manager *MultiS3Manager) http.HandlerFunc {
1818
return func(w http.ResponseWriter, r *http.Request) {
1919
instances := manager.GetAllInstances()
2020
current := manager.GetCurrentInstance()
21-
21+
2222
response := struct {
2323
Instances []S3InstanceInfo `json:"instances"`
2424
Current string `json:"current"`
2525
}{
2626
Instances: make([]S3InstanceInfo, len(instances)),
2727
Current: current.ID,
2828
}
29-
29+
3030
for i, instance := range instances {
3131
response.Instances[i] = S3InstanceInfo{
3232
ID: instance.ID,
3333
Name: instance.Name,
3434
}
3535
}
36-
36+
3737
w.Header().Set("Content-Type", "application/json")
3838
json.NewEncoder(w).Encode(response)
3939
}
@@ -44,25 +44,25 @@ func HandleSwitchS3Instance(manager *MultiS3Manager) http.HandlerFunc {
4444
return func(w http.ResponseWriter, r *http.Request) {
4545
vars := mux.Vars(r)
4646
instanceID := vars["instanceId"]
47-
47+
4848
if instanceID == "" {
4949
http.Error(w, "instance ID is required", http.StatusBadRequest)
5050
return
5151
}
52-
52+
5353
err := manager.SetCurrentInstance(instanceID)
5454
if err != nil {
5555
http.Error(w, err.Error(), http.StatusNotFound)
5656
return
5757
}
58-
58+
5959
current := manager.GetCurrentInstance()
6060
response := S3InstanceInfo{
6161
ID: current.ID,
6262
Name: current.Name,
6363
}
64-
64+
6565
w.Header().Set("Content-Type", "application/json")
6666
json.NewEncoder(w).Encode(response)
6767
}
68-
}
68+
}

internal/app/s3manager/manager_handlers.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
// HandleBucketsViewWithManager renders all buckets on an HTML page using MultiS3Manager.
1616
func HandleBucketsViewWithManager(manager *MultiS3Manager, templates fs.FS, allowDelete bool, rootURL string) http.HandlerFunc {
1717
type pageData struct {
18-
RootURL string
19-
Buckets []interface{}
20-
AllowDelete bool
21-
CurrentS3 *S3Instance
22-
S3Instances []*S3Instance
23-
HasError bool
24-
ErrorMessage string
18+
RootURL string
19+
Buckets []interface{}
20+
AllowDelete bool
21+
CurrentS3 *S3Instance
22+
S3Instances []*S3Instance
23+
HasError bool
24+
ErrorMessage string
2525
}
2626

2727
return func(w http.ResponseWriter, r *http.Request) {
@@ -30,7 +30,7 @@ func HandleBucketsViewWithManager(manager *MultiS3Manager, templates fs.FS, allo
3030
instances := manager.GetAllInstances()
3131

3232
buckets, err := s3.ListBuckets(r.Context())
33-
33+
3434
data := pageData{
3535
RootURL: rootURL,
3636
AllowDelete: allowDelete,
@@ -70,7 +70,7 @@ func HandleBucketViewWithManager(manager *MultiS3Manager, templates fs.FS, allow
7070
s3 := manager.GetCurrentClient()
7171
current := manager.GetCurrentInstance()
7272
instances := manager.GetAllInstances()
73-
73+
7474
// Create a modified handler that includes S3 instance data
7575
handler := createBucketViewWithS3Data(s3, templates, allowDelete, listRecursive, rootURL, current, instances)
7676
handler(w, r)
@@ -150,16 +150,16 @@ func createBucketViewWithS3Data(s3 S3, templates fs.FS, allowDelete bool, listRe
150150
}
151151

152152
type pageData struct {
153-
RootURL string
154-
BucketName string
155-
Objects []objectWithIcon
156-
AllowDelete bool
157-
Paths []string
158-
CurrentPath string
159-
CurrentS3 *S3Instance
160-
S3Instances []*S3Instance
161-
HasError bool
162-
ErrorMessage string
153+
RootURL string
154+
BucketName string
155+
Objects []objectWithIcon
156+
AllowDelete bool
157+
Paths []string
158+
CurrentPath string
159+
CurrentS3 *S3Instance
160+
S3Instances []*S3Instance
161+
HasError bool
162+
ErrorMessage string
163163
}
164164

165165
return func(w http.ResponseWriter, r *http.Request) {
@@ -171,7 +171,7 @@ func createBucketViewWithS3Data(s3 S3, templates fs.FS, allowDelete bool, listRe
171171
var objs []objectWithIcon
172172
hasError := false
173173
errorMessage := ""
174-
174+
175175
opts := minio.ListObjectsOptions{
176176
Recursive: listRecursive,
177177
Prefix: path,
@@ -202,7 +202,7 @@ func createBucketViewWithS3Data(s3 S3, templates fs.FS, allowDelete bool, listRe
202202
}
203203
objs = append(objs, obj)
204204
}
205-
205+
206206
data := pageData{
207207
RootURL: rootURL,
208208
BucketName: bucketName,
@@ -227,4 +227,4 @@ func createBucketViewWithS3Data(s3 S3, templates fs.FS, allowDelete bool, listRe
227227
return
228228
}
229229
}
230-
}
230+
}

internal/app/s3manager/multi_s3_manager.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ type S3Instance struct {
2020

2121
// MultiS3Manager manages multiple S3 instances
2222
type MultiS3Manager struct {
23-
instances map[string]*S3Instance
24-
currentID string
25-
instanceOrder []string
26-
mu sync.RWMutex
23+
instances map[string]*S3Instance
24+
currentID string
25+
instanceOrder []string
26+
mu sync.RWMutex
2727
}
2828

2929
// S3InstanceConfig holds configuration for a single S3 instance
@@ -49,17 +49,17 @@ func NewMultiS3Manager(configs []S3InstanceConfig) (*MultiS3Manager, error) {
4949

5050
for i, config := range configs {
5151
instanceID := fmt.Sprintf("%d", i+1)
52-
52+
5353
// Set up S3 client options
5454
opts := &minio.Options{
5555
Secure: config.UseSSL,
5656
}
57-
57+
5858
if config.UseIam {
5959
opts.Creds = credentials.NewIAM(config.IamEndpoint)
6060
} else {
6161
var signatureType credentials.SignatureType
62-
62+
6363
switch config.SignatureType {
6464
case "V2":
6565
signatureType = credentials.SignatureV2
@@ -72,43 +72,43 @@ func NewMultiS3Manager(configs []S3InstanceConfig) (*MultiS3Manager, error) {
7272
default:
7373
return nil, fmt.Errorf("invalid SIGNATURE_TYPE: %s", config.SignatureType)
7474
}
75-
75+
7676
opts.Creds = credentials.NewStatic(config.AccessKeyID, config.SecretAccessKey, "", signatureType)
7777
}
78-
78+
7979
if config.Region != "" {
8080
opts.Region = config.Region
8181
}
82-
82+
8383
if config.UseSSL && config.SkipSSLVerification {
8484
opts.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} //nolint:gosec
8585
}
86-
86+
8787
// Create S3 client
8888
s3Client, err := minio.New(config.Endpoint, opts)
8989
if err != nil {
9090
return nil, fmt.Errorf("error creating s3 client for instance %s: %w", config.Name, err)
9191
}
92-
92+
9393
instance := &S3Instance{
9494
ID: instanceID,
9595
Name: config.Name,
9696
Client: s3Client,
9797
}
98-
98+
9999
manager.instances[instanceID] = instance
100100
manager.instanceOrder = append(manager.instanceOrder, instanceID)
101-
101+
102102
// Set the first instance as current
103103
if i == 0 {
104104
manager.currentID = instanceID
105105
}
106106
}
107-
107+
108108
if len(manager.instances) == 0 {
109109
return nil, fmt.Errorf("no S3 instances configured")
110110
}
111-
111+
112112
log.Printf("Initialized MultiS3Manager with %d instances", len(manager.instances))
113113
return manager, nil
114114
}
@@ -117,7 +117,7 @@ func NewMultiS3Manager(configs []S3InstanceConfig) (*MultiS3Manager, error) {
117117
func (m *MultiS3Manager) GetCurrentClient() S3 {
118118
m.mu.RLock()
119119
defer m.mu.RUnlock()
120-
120+
121121
instance, exists := m.instances[m.currentID]
122122
if !exists && len(m.instances) > 0 {
123123
// Fallback to first instance if current doesn't exist
@@ -131,7 +131,7 @@ func (m *MultiS3Manager) GetCurrentClient() S3 {
131131
func (m *MultiS3Manager) GetCurrentInstance() *S3Instance {
132132
m.mu.RLock()
133133
defer m.mu.RUnlock()
134-
134+
135135
instance, exists := m.instances[m.currentID]
136136
if !exists && len(m.instances) > 0 {
137137
// Fallback to first instance if current doesn't exist
@@ -145,11 +145,11 @@ func (m *MultiS3Manager) GetCurrentInstance() *S3Instance {
145145
func (m *MultiS3Manager) SetCurrentInstance(instanceID string) error {
146146
m.mu.Lock()
147147
defer m.mu.Unlock()
148-
148+
149149
if _, exists := m.instances[instanceID]; !exists {
150150
return fmt.Errorf("S3 instance with ID %s not found", instanceID)
151151
}
152-
152+
153153
m.currentID = instanceID
154154
log.Printf("Switched to S3 instance: %s (%s)", instanceID, m.instances[instanceID].Name)
155155
return nil
@@ -159,10 +159,10 @@ func (m *MultiS3Manager) SetCurrentInstance(instanceID string) error {
159159
func (m *MultiS3Manager) GetAllInstances() []*S3Instance {
160160
m.mu.RLock()
161161
defer m.mu.RUnlock()
162-
162+
163163
instances := make([]*S3Instance, 0, len(m.instanceOrder))
164164
for _, id := range m.instanceOrder {
165165
instances = append(instances, m.instances[id])
166166
}
167167
return instances
168-
}
168+
}

main.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ type s3InstanceConfig struct {
3636
}
3737

3838
type configuration struct {
39-
S3Instances []s3InstanceConfig
40-
AllowDelete bool
41-
ForceDownload bool
42-
ListRecursive bool
43-
Port string
44-
Timeout int32
45-
SseType string
46-
SseKey string
39+
S3Instances []s3InstanceConfig
40+
AllowDelete bool
41+
ForceDownload bool
42+
ListRecursive bool
43+
Port string
44+
Timeout int32
45+
SseType string
46+
SseKey string
4747
}
4848

4949
func parseConfiguration() configuration {
@@ -55,7 +55,7 @@ func parseConfiguration() configuration {
5555
prefix := fmt.Sprintf("%d_", i)
5656
name := viper.GetString(prefix + "NAME")
5757
endpoint := viper.GetString(prefix + "ENDPOINT")
58-
58+
5959
// If NAME or ENDPOINT is not found, stop parsing
6060
if name == "" || endpoint == "" {
6161
break
@@ -66,13 +66,13 @@ func parseConfiguration() configuration {
6666
useIam := viper.GetBool(prefix + "USE_IAM")
6767
iamEndpoint := viper.GetString(prefix + "IAM_ENDPOINT")
6868
region := viper.GetString(prefix + "REGION")
69-
69+
7070
viper.SetDefault(prefix+"USE_SSL", true)
7171
useSSL := viper.GetBool(prefix + "USE_SSL")
72-
72+
7373
viper.SetDefault(prefix+"SKIP_SSL_VERIFICATION", false)
7474
skipSSLVerification := viper.GetBool(prefix + "SKIP_SSL_VERIFICATION")
75-
75+
7676
viper.SetDefault(prefix+"SIGNATURE_TYPE", "V4")
7777
signatureType := viper.GetString(prefix + "SIGNATURE_TYPE")
7878

@@ -185,11 +185,11 @@ func main() {
185185
r := mux.NewRouter()
186186
r.Handle("/", http.RedirectHandler("/buckets", http.StatusPermanentRedirect)).Methods(http.MethodGet)
187187
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.FS(statics)))).Methods(http.MethodGet)
188-
188+
189189
// S3 instance management endpoints
190190
r.Handle("/api/s3-instances", s3manager.HandleGetS3Instances(s3Manager)).Methods(http.MethodGet)
191191
r.Handle("/api/s3-instances/{instanceId}/switch", s3manager.HandleSwitchS3Instance(s3Manager)).Methods(http.MethodPost)
192-
192+
193193
// S3 management endpoints (using current instance)
194194
r.Handle("/buckets", s3manager.HandleBucketsViewWithManager(s3Manager, templates, configuration.AllowDelete, rootURL)).Methods(http.MethodGet)
195195
r.PathPrefix("/buckets/").Handler(s3manager.HandleBucketViewWithManager(s3Manager, templates, configuration.AllowDelete, configuration.ListRecursive, rootURL)).Methods(http.MethodGet)

0 commit comments

Comments
 (0)