Ben Chuanlong Du's Blog

It is never too late to learn.

Get Information of User in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Get Information of the Current User

user.Current() returns information of the current (real) user. If the code is run by a non-root user named some_user on Linux, then information of some_user is returned. However, if some_user has sudo

Hands on Array in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comment

  1. Array in Golang is similar to Array in Rust in the sense that the length of an array is part of its type and must be determined at compile time.

  2. Array is a primitive (value) type in Golang. When assigned to another variable or passed as a parameter, it is copied! For this reason, array is not a good interface to use. Slice is prefer to array for function parameters.

Hands on the Cobra Module in Golang

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Comments

  1. Cobra support groups of flags which appear together or are mutually exclusive. For detailed discussions, please refer to Flag Groups .

Quickly Start a Cobra-based project

Below is an example of creating a cobra-based project "icon".

Split String into Rows in SQL

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

split

SELECT
    A.state,
    split.A.value('.', 'VARCHAR(100)') AS String
FROM (
    SELECT 
        state,  
        CAST('<M>' + REPLACE(city, ',', '</M><M>') + '</M>' AS XML) AS string  
    FROM
        TableA
    ) AS A
CROSS APPLY String.nodes ('/M') AS split(a)