Created
July 4, 2020 08:27
-
-
Save SyureNyanko/4f746fa8f638383c4c8e58ec81d24934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http/httptest" | |
"net/http/httputil" | |
"net/url" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
func awsS3(endpoint string) { | |
svc := s3.New(session.New(), &aws.Config{ | |
Region: aws.String("us-east-1"), | |
Credentials: credentials.NewStaticCredentialsFromCreds( | |
credentials.Value{ | |
AccessKeyID: "*", | |
SecretAccessKey: "*", | |
}), | |
Endpoint: aws.String(endpoint), | |
}) | |
result, err := svc.ListBuckets(nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("Buckets:") | |
for _, b := range result.Buckets { | |
fmt.Printf("* %s created on %s\n", aws.StringValue(b.Name), aws.TimeValue(b.CreationDate)) | |
} | |
} | |
func main() { | |
backendURL := "http://127.0.0.1:9000" | |
rpURL, err := url.Parse(backendURL) | |
if err != nil { | |
fmt.Println("parse error", backendURL) | |
} | |
frontendProxy := httptest.NewServer(httputil.NewSingleHostReverseProxy(rpURL)) | |
defer frontendProxy.Close() | |
fmt.Println(frontendProxy.URL) | |
awsS3(frontendProxy.URL) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment