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 Logger interface { | |
Println(v ...interface{}) | |
Fatalln(v ...interface{}) | |
} | |
type Logrus struct { | |
*logrus.Logger | |
} | |
func (l *Logrus) Println(v ...interface{}) { |
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 Database interface { | |
Insert(data interface{}) error | |
Retrieve(id string) (interface{}, error) | |
} | |
type MySQL struct { | |
connection *sql.DB | |
} | |
func (m *MySQL) Insert(data interface{}) 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
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
type LegacyService struct { | |
} |
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" | |
type LegacyPrinter struct { | |
} | |
func (l *LegacyPrinter) Print(s string) { | |
fmt.Println(s) | |
} |
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 Database interface { | |
SaveData(data string) error | |
} | |
type MySQL struct { | |
// fields and methods | |
} | |
func (m *MySQL) SaveData(data string) error { | |
// code to save data to MySQL |
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 Singleton struct { | |
count int | |
} | |
var instance *Singleton | |
func GetInstance() *Singleton { | |
if instance == nil { | |
instance = &Singleton{} | |
} |
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 Config struct { | |
// fields and methods | |
} | |
var config *Config | |
func GetConfig() *Config { | |
if config == nil { | |
config = &Config{} | |
} |
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 Database struct { | |
// fields and methods | |
} | |
var db *Database | |
func GetDatabase() *Database { | |
if db == nil { | |
db = &Database{} | |
} |
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 Logger struct { | |
file *os.File | |
} | |
func (l *Logger) Log(message string) { | |
_, _ = l.file.WriteString(message + "\n") | |
} | |
var logger *Logger |
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 Person struct { | |
Name string | |
Age int | |
} | |
func (p *Person) Greet() string { | |
return "Hello, my name is " + p.Name | |
} | |
func (p *Person) Copy() *Person { |