47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.3 KiB
3.3 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, params, output, tested, tests, test_file_path, file_path
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | params | output | tested | tests | test_file_path | file_path | |||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| s3_upload | function | go | infra | 1.0.0 | impure | func S3Upload(cfg S3Config, key string, data io.Reader, contentType string) error | STUB. Sube data a un bucket S3-compatible (AWS S3, MinIO, etc) bajo la key indicada con el Content-Type dado. La implementacion real requiere github.com/aws/aws-sdk-go-v2. |
|
|
false | error_go_core |
|
|
nil si la subida fue exitosa, error si fallo. STUB actual retorna siempre error "not implemented" | false | functions/infra/s3_upload.go |
Estado
Stub. Para activar la implementacion real:
- Anadir dependencias:
go get github.com/aws/aws-sdk-go-v2/aws go get github.com/aws/aws-sdk-go-v2/config go get github.com/aws/aws-sdk-go-v2/credentials go get github.com/aws/aws-sdk-go-v2/service/s3 - Reemplazar el cuerpo del stub por:
import ( "context" "github.com/aws/aws-sdk-go-v2/aws" awscfg "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/s3" ) func S3Upload(cfg S3Config, key string, data io.Reader, contentType string) error { ctx := context.Background() awsCfg, err := awscfg.LoadDefaultConfig(ctx, awscfg.WithRegion(cfg.Region), awscfg.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( cfg.AccessKey, cfg.SecretKey, "")), ) if err != nil { return fmt.Errorf("s3_upload: aws config: %w", err) } client := s3.NewFromConfig(awsCfg, func(o *s3.Options) { o.UsePathStyle = true if cfg.Endpoint != "" { scheme := "http" if cfg.UseSSL { scheme = "https" } o.BaseEndpoint = aws.String(fmt.Sprintf("%s://%s", scheme, cfg.Endpoint)) } }) _, err = client.PutObject(ctx, &s3.PutObjectInput{ Bucket: aws.String(cfg.Bucket), Key: aws.String(key), Body: data, ContentType: aws.String(contentType), }) return err }
Ejemplo (con implementacion real)
cfg := S3Config{
Endpoint: "s3.amazonaws.com",
Bucket: "mi-bucket",
AccessKey: os.Getenv("S3_ACCESS_KEY"),
SecretKey: os.Getenv("S3_SECRET_KEY"),
Region: "us-east-1",
UseSSL: true,
}
f, _ := os.Open("./uploads/photo.png")
defer f.Close()
err := S3Upload(cfg, "images/photo.png", f, "image/png")
Notas
Compatible con AWS S3, MinIO, Wasabi y otros S3-compatible. El campo UsePathStyle = true es necesario para MinIO y para algunos endpoints custom; AWS S3 nativo soporta tanto path-style como virtual-hosted-style.