Created
January 27, 2023 09:53
-
-
Save arriqaaq/6fa7f21210c64d11662256fd3a65d4f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"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