This commit is contained in:
Alexander Pivkin 2026-01-23 14:35:54 +03:00
parent 23e5e11a1d
commit 95f257a4d0
4 changed files with 95 additions and 0 deletions

View 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
View File

@ -0,0 +1,3 @@
module main
go 1.25.6

19
goroutines/main.go Normal file
View 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)
}
}

View File

@ -78,6 +78,7 @@ func main() {
// HTTP runs in separate thread cuz it blocks further execution of main // HTTP runs in separate thread cuz it blocks further execution of main
go func() { go func() {
fmt.Fprint()
mainlogger.Info("Starting http server") mainlogger.Info("Starting http server")
// Here I check for errors if HTTP fails // Here I check for errors if HTTP fails
if err := server.ListenAndServe(); err != nil { if err := server.ListenAndServe(); err != nil {