Golang

Member

braden_wiegand

by braden_wiegand , in category: Golang , 13 days ago
no answers

Check if sum of numbers are equal 😁

1
2
3
func sumEqual(u, v, w float64) bool {
	return (u+v == w) && (u == w-v) && (v == w-u)
}


Member

letha

by letha , in category: Golang , 18 days ago
no answers

Factory Method Pattern In Golang 😁

1
2
3
4
5
6
7
8
9
func getTransport(tt string) (iTransport, error) {
	if tt == "scooter" {
		return newElectricScooter(), nil
	}
	if tt == "quadcopter" {
		return newQuadcopter(), nil
	}
	return nil, fmt.Errorf("Wrong type")
}


Member

makayla.beahan

How to check if empty name in Golang multi languages 😝

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
func (svc *UserSvc) isEmptyName(name model.User_Name) bool {
  if name.First.RU == "" {
    if name.First.EN == "" {
      if name.First.TR == "" {
        if name.First.IT == "" {
          if name.Last.RU == "" {
            if name.Last.EN == "" {
              if name.Last.TR == "" {
                if name.Last.IT == "" {
                  return true
                }
              }
            }
          }
        }
      }
    }
  }
  return false
}


Member

makayla.beahan

by makayla.beahan , in category: Golang , 20 days ago
no answers

Defer and sleep in Golang 😁

1
2
3
4
5
6
func GetUser() *User {
    defer func() {
        time.Sleep(100 * time.Millisecond)
    }()
    return &User{}
}


Member

jerald_rippin

by jerald_rippin , in category: Golang , 20 days ago
no answers

Nice error handling in Golang 🀣


1
2
3
4
5
6
7
8
9
func (c *Client) DeleteFile(filename string) {
	_, err := s3.New(c.session).DeleteObject(&s3.DeleteObjectInput{
		Bucket: aws.String(c.bucket),
		Key:    aws.String(filename),
	})
	if err != nil {
		return
	}
}


Member

lou_lindgren

Very informative variables in nested loop πŸ˜ƒ ok -> okk -> okkk ....It might be okkkkkkkkkkkkkkkkkkkkkkkkkkkk in the end 😁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if user, ok := db.User[userId]; ok {
    for _, cardId := range user.CardIds {
        if card, okk := db.Card[cardId]; okk {
            if notif, okkk := db.Notif[card.NotifId]; okkk {
                card_notifs = append(card_notifs, CardNotif{card.Id, card, notif})
            }
        }
    }     
    c.JSON(http.StatusOK, card_notifs)
} else {  
    c.String(http.StatusNotFound, "")
}