*** This post is copyright from #mobilespoon. ***

Reading back this post from December 2018, it seems that not much has changed, and many of the trends are still happening: chromeless designs, gestures, gradients, deep flat, big bold fonts, and more, they are still here and will remain dominant during 2020.

Here’s a closer look at some new mobile trends that will continue to grow in 2020:

1. Dark mode

Yep, I know that’s old news already, but you know what they say: “once apple decides to go black, no one can go back…”. …


Using a Filename as an Input

Another common mistake is to pass a filename to a function.

Let’s say we have to implement a function to count the number of empty lines in a file. The most natural implementation would be something like this:

filename is given as an input, so we open it and then we implement our logic, right?

func count(filename string) (int, error) {
file, err := os.Open(filename)
if err != nil {
return 0, errors.Wrapf(err, "unable to open %s", filename)
}
defer file.Close()

scanner := bufio.NewScanner(file)
count := 0
for scanner.Scan() {
if scanner.Text()


Structs in Golang represent one of the most common variable types and used practically everywhere, from dealing with configuration options to marshaling of JSON or XML documents using encoding/json or encoding/xml packages. Field tags are part of the struct's field definition and allow nice and easy way to store meta data about fields for many use cases (field mapping, data validation, ORM, etc).

Basics

What’s interesting about structs in general? One of the most useful features of the struct is ability to specify field name mapping. It comes very handy if you deal with external services and do a lot of…


Việc khởi tạo và thực thi chương trình Go luôn bắt đầu từ hàm main.main. Nếu package main có import các package khác, chúng sẽ được thêm vào package main theo thứ tự khai báo.

init không phải là hàm thông thường, nó có thể có nhiều định nghĩa, và các hàm khác không thể sử dụng nó.

  • Nếu một package được import nhiều lần, sẽ chỉ được tính là một khi thực thi.
  • Khi một package được import mà nó lại import các package khác, trước tiên Go sẽ import các package khác đó trước, sau đó khởi tạo…

Luu Duc Hoang

Loving with Golang

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store