Skip to content

Instantly share code, notes, and snippets.

@nwjlyons
Last active July 18, 2020 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwjlyons/404070a0ea36ef2daa7cbdc50ebfe287 to your computer and use it in GitHub Desktop.
Save nwjlyons/404070a0ea36ef2daa7cbdc50ebfe287 to your computer and use it in GitHub Desktop.
Adaptor pattern in Go
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