Last active
July 18, 2020 11:10
-
-
Save nwjlyons/404070a0ea36ef2daa7cbdc50ebfe287 to your computer and use it in GitHub Desktop.
Adaptor pattern in Go
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" | |
type StorageAdaptor interface { | |
Save(string) | |
Delete(string) | |
} | |
type StorageAdaptorLocal struct { | |
Location string | |
} | |
func (StorageAdaptorLocal) Save(path string) { | |
fmt.Println("saving to local file system") | |
} | |
func (StorageAdaptorLocal) Delete(path string) { | |
fmt.Println("deleting from local file system") | |
} | |
type StorageAdaptorS3 struct { | |
AccessKey string | |
SecretAccessKey string | |
Bucket string | |
} | |
func (StorageAdaptorS3) Save(path string) { | |
fmt.Println("saving to S3") | |
} | |
func (StorageAdaptorS3) Delete(path string) { | |
fmt.Println("deleting from S3") | |
} | |
var store StorageAdaptor | |
func main() { | |
//store = StorageAdaptorLocal{Location: "/uploads"} | |
store = StorageAdaptorS3{AccessKey: "x", SecretAccessKey: "x", Bucket: "x"} | |
store.Save("file.go") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment