sdf
This commit is contained in:
parent
23e5e11a1d
commit
95f257a4d0
72
100_errors_go/interfaces/main.go
Normal file
72
100_errors_go/interfaces/main.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package main
|
||||
|
||||
BAD
|
||||
// Producer
|
||||
|
||||
type CustomerStorage interface {
|
||||
StoreCustomer(customer string) error
|
||||
GetCustomer(is string) error
|
||||
UpdateCustomer(customer string) error
|
||||
GetAllCustomers() ([]string,error)
|
||||
GetCustomerWithoutContract() ([]string,error)
|
||||
}
|
||||
|
||||
//======================================
|
||||
|
||||
|
||||
// Consumer
|
||||
|
||||
type customerGetter interface {
|
||||
GetAllCustomers() ([]string,error)
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===================================================================
|
||||
|
||||
type IntConfig struct {
|
||||
// ...
|
||||
}
|
||||
|
||||
func (c IntConfig) Get() int { <======== PRODUCER
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c IntConfig) Set(value int) {
|
||||
//...
|
||||
}
|
||||
|
||||
|
||||
|
||||
Consumer
|
||||
|
||||
type confifSetter interface{
|
||||
Set()
|
||||
}
|
||||
|
||||
type configGetter interface {
|
||||
Get() int
|
||||
}
|
||||
|
||||
type Mixed interface {
|
||||
confifSetter
|
||||
configGetter
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
type Foo struct {
|
||||
threshold configGetter
|
||||
}
|
||||
|
||||
func NewFoo(new_threshold configGetter) Foo {
|
||||
return Foo{threshold: new_threshold}
|
||||
}
|
||||
|
||||
func (f Foo) Bar() {
|
||||
threshold := f.threshold.Get()
|
||||
}
|
||||
3
goroutines/go.mod
Normal file
3
goroutines/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module main
|
||||
|
||||
go 1.25.6
|
||||
19
goroutines/main.go
Normal file
19
goroutines/main.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func Route(i int, ch chan<- int) {
|
||||
ch <- i
|
||||
}
|
||||
|
||||
func main() {
|
||||
ch := make(chan int)
|
||||
|
||||
for i:= range 10 {
|
||||
go Route(i, ch)
|
||||
}
|
||||
|
||||
for i := range ch {
|
||||
fmt.Println(i)
|
||||
}
|
||||
}
|
||||
|
|
@ -78,6 +78,7 @@ func main() {
|
|||
|
||||
// HTTP runs in separate thread cuz it blocks further execution of main
|
||||
go func() {
|
||||
fmt.Fprint()
|
||||
mainlogger.Info("Starting http server")
|
||||
// Here I check for errors if HTTP fails
|
||||
if err := server.ListenAndServe(); err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user