Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 27, 2023 09:53
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 arriqaaq/6fa7f21210c64d11662256fd3a65d4f0 to your computer and use it in GitHub Desktop.
Save arriqaaq/6fa7f21210c64d11662256fd3a65d4f0 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
)
// FileSystem is the facade interface
type FileSystem interface {
ReadFile(string) ([]byte, error)
WriteFile(string, []byte, int) error
}
// FileSystemImpl is the struct that implements the facade interface
type FileSystemImpl struct{}
func (fs *FileSystemImpl) ReadFile(path string) ([]byte, error) {
return ioutil.ReadFile(path)
}
func (fs *FileSystemImpl) WriteFile(path string, data []byte, perm int) error {
return ioutil.WriteFile(path, data, perm)
}
func main() {
var fs FileSystem = &FileSystemImpl{}
data, _ := fs.ReadFile("test.txt")
fmt.Println(string(data))
fs.WriteFile("test.txt", []byte("Hello, World!"), 0644)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment