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 ( | |
| "encoding/json" | |
| "fmt" | |
| ) | |
| type Person struct { | |
| Name string | |
| Age int |
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" | |
| "net/http" | |
| ) | |
| func main() { | |
| client := &http.Client{} | |
| req, _ := http.NewRequest("GET", "https://www.example.com", nil) |
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) |
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
| type Middleware func(http.HandlerFunc) http.HandlerFunc | |
| func LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc { | |
| return func(w http.ResponseWriter, r *http.Request) { | |
| log.Println("Before request") | |
| next.ServeHTTP(w, r) | |
| log.Println("After request") | |
| } | |
| } |
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
| import ( | |
| "io" | |
| "strings" | |
| ) | |
| func main() { | |
| r1 := strings.NewReader("first reader ") | |
| r2 := strings.NewReader("second reader ") | |
| r3 := strings.NewReader("third reader") | |
| r := io.MultiReader(r1, r2, r3) |
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 pizza | |
| type Pizza interface { | |
| GetPrice() float64 | |
| GetDescription() string | |
| } | |
| type Margherita struct{} | |
| func (m *Margherita) GetPrice() float64 { |
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 network | |
| type NetworkElement interface { | |
| // methods to interact with the element | |
| GetName() string | |
| GetType() string | |
| } | |
| type Router struct { | |
| name string |
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" | |
| // Shape is the interface that all shapes must implement | |
| type Shape interface { | |
| Area() float64 | |
| } | |
| // Rectangle represents a rectangle shape |
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
| type GUI interface { | |
| Draw() | |
| HandleEvent(event interface{}) | |
| } | |
| type Button struct { | |
| x, y, width, height int | |
| label string | |
| } |
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
| type FileSystem interface { | |
| Open() (io.ReadCloser, error) | |
| List() ([]string, error) | |
| } | |
| type File struct { | |
| name string | |
| path string | |
| } |