Перейти к содержимому

Wildberries / WB - 12

  • Что в Go устраивает, а что не нравится? go/stdlib-tooling
  • Больше нравится кодить или заниматься управлением? hr-behavioral/about-you
  • Как оценивали задачи в команде? hr-behavioral/teamwork
  • Что ищешь в новой работе, что привлекает? hr-behavioral/motivation
  • Были ли конфликты среди других разработчиков и если дa, то как их решали? hr-behavioral/teamwork
  • Читал ли про новые фитчи Go 1.24 и если дa, то что понравилось? go/stdlib-tooling
  • Использовали ли у себя дженерики? go/generics
  • Использовали ли у себя постгрес и если дa, то какие интересные задачи решали с ее помощью? sql/general
  • Какие бывают типы индексов? sql/indexes
  • Что такое view? sql/general
  • Что такое нормализованная форма? sql/schema-design
  • Нормализованная и денормализованная будет меньше занимает место на диске? sql/schema-design
  • Какая из них будет быстрее работать при обычном селекте? sql/query-optimization
  • Работал ли с mq rabbit? brokers/rabbitmq
  • Чем kafka отличается от mq rabbit? brokers/kafka
type parrotType int
const (
TypeEuropean parrotType = 1
TypeAfrican parrotType = 2
TypeNorwegianBlue parrotType = 3
)
// Parrot has a Speed.
type Parrot interface {
Speed() (float64, error)
}
type mixedParrot struct {
_type parrotType
numberOfCoconuts int
voltage float64
nailed bool
}
func CreateParrot(pt parrotType, numberOfCoconuts int, voltage float64, nailed bool) Parrot {
return mixedParrot{
_type: pt,
numberOfCoconuts: numberOfCoconuts,
voltage: voltage,
nailed: nailed,
}
}
func (parrot mixedParrot) Speed() (float64, error) {
switch parrot._type {
case TypeEuropean:
return parrot.baseSpeed(), nil
case TypeAfrican:
return math.Max(0, parrot.baseSpeed()-parrot.loadFactor()*float64(parrot.numberOfCoconuts)), nil
case TypeNorwegianBlue:
if parrot.nailed {
return 0, nil
}
return parrot.computeBaseSpeedForVoltage(parrot.voltage), nil
default:
return 0, errors.New("should be unreachable ")
}
}
func (parrot mixedParrot) computeBaseSpeedForVoltage(voltage float64) float64 {
return math.Min(24.0, voltage*parrot.baseSpeed())
}
func (parrot mixedParrot) loadFactor() float64 {
return 9.0
}
func (parrot mixedParrot) baseSpeed() float64 {
return 12.0
}

Задача: Какие проблемы есть в коде? Как исправить? Должно вывестись в консоль &{0 true} &{1 true} &{4 true} &{5 true}. security/crypto

Заголовок раздела «Задача: Какие проблемы есть в коде? Как исправить? Должно вывестись в консоль &{0 true} &{1 true} &{4 true} &{5 true}. security/crypto»
type Agent struct {
ID int
Enabled bool
}
func (a Agent) Enable() {
a.Enabled = true
}
type Enabler interface {
Enable()
}
func main() {
agents := make([]*Agent, 0, 5)
for i := 0; i < 2; i++ {
agents = append(agents, &Agent{ID: i})
}
addThirdPartyAgents(agents)
pipe := make(chan Enabler)
var wg sync.WaitGroup
wg.Add(2)
go pipeSend(pipe, agents, &wg)
go pipeEnableProcess(pipe, &wg)
wg.Wait()
}
func addThirdPartyAgents(agents []*Agent) {
thirdParty := []*Agent{
{ID: 4},
{ID: 5},
}
agents = append(agents, thirdParty...)
}
func pipeSend(pipe chan Enabler, agents []*Agent, wg *sync.WaitGroup) {
defer wg.Done()
for _, а := range agents {
pipe <- a
}
close(pipe)
}
func pipeEnableProcess(pipe chan Enabler, wg *sync.WaitGroup) {
defer wg.Done()
for {
select {
case a := <-pipe:
a.Enable()
dbWrite(a) // «Сохраняем» и печатаем
}
}
}
var dbWrite = func(a any) {
fmt.Println(a)
time.Sleep(time.Second * 1)
}