Cloud-oriented Life

Cloud Native Technology Improves Lives

excelize

Introduction

Excelize is a library written in pure Go providing a set of functions that allow you to write to and read from XLSX / XLSM / XLTM files. Supports reading and writing spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports complex components by high compatibility, and provided streaming API for generating or reading data from a worksheet with huge amounts of data. This library needs Go version 1.15 or later. The full API docs can be seen using go’s built-in documentation tool, or online at go.dev and docs reference.

Read more »

YAML support for the Go language

The yaml package enables Go programs to comfortably encode and decode YAML values. It was developed within Canonical as part of the juju project, and is based on a pure Go port of the well-known libyaml C library to parse and generate YAML data quickly and reliably.

Installation

Standard go get:

1
$ go get -u gopkg.in/yaml.v2

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main

import (
"fmt"
"log"

"gopkg.in/yaml.v2"
)

var data = `
a: Easy!
b:
c: 2
d: [3, 4]
`

// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type T struct {
A string
B struct {
RenamedC int `yaml:"c"`
D []int `yaml:",flow"`
}
}

func main() {
t := T{}

err := yaml.Unmarshal([]byte(data), &t)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- t:\n%v\n\n", t)

d, err := yaml.Marshal(&t)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- t dump:\n%s\n\n", string(d))

m := make(map[interface{}]interface{})

err = yaml.Unmarshal([]byte(data), &m)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- m:\n%v\n\n", m)

d, err = yaml.Marshal(&m)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("--- m dump:\n%s\n\n", string(d))
}

This example will generate the following output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--- t:
{Easy! {2 [3 4]}}

--- t dump:
a: Easy!
b:
c: 2
d: [3, 4]


--- m:
map[a:Easy! b:map[c:2 d:[3 4]]]

--- m dump:
a: Easy!
b:
c: 2
d:
- 3
- 4

FAQs

yaml:",flow"

References

[1] GitHub - go-yaml/yaml: YAML support for the Go language. - https://github.com/go-yaml/yaml

[2] yaml · pkg.go.dev - https://pkg.go.dev/gopkg.in/yaml.v2

sshuttle

As far as I know, sshuttle is the only program that solves the following common case:

  • Your client machine (or router) is Linux, FreeBSD, or MacOS.

  • You have access to a remote network via ssh.

  • You don’t necessarily have admin access on the remote network.

  • The remote network has no VPN, or only stupid/complex VPN protocols (IPsec, PPTP, etc). Or maybe you are the admin and you just got frustrated with the awful state of VPN tools.

  • You don’t want to create an ssh port forward for every single host/port on the remote network.

  • You hate openssh’s port forwarding because it’s randomly slow and/or stupid.

  • You can’t use openssh’s PermitTunnel feature because it’s disabled by default on openssh servers; plus it does TCP-over-TCP, which has terrible performance.

Read more »

GORM

The fantastic ORM library for Golang aims to be developer friendly.

Overview

  • Full-Featured ORM

  • Associations (Has One, Has Many, Belongs To, Many To Many, Polymorphism, Single-table inheritance)

  • Hooks (Before/After Create/Save/Update/Delete/Find)

  • Eager loading with Preload, Joins

  • Transactions, Nested Transactions, Save Point, RollbackTo to Saved Point

  • Context, Prepared Statement Mode, DryRun Mode

  • Batch Insert, FindInBatches, Find/Create with Map, CRUD with SQL Expr and Context Valuer

  • SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints, Named Argument, SubQuery

  • Composite Primary Key, Indexes, Constraints

  • Auto Migrations

  • Logger

  • Extendable, flexible plugin API: Database Resolver (Multiple Databases, Read/Write Splitting) / Prometheus…

  • Every feature comes with tests

  • Developer Friendly

Installation

1
2
3
$ go get -u gorm.io/gorm

$ go get -u gorm.io/driver/sqlite

Quick Start

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
"gorm.io/gorm"
"gorm.io/driver/sqlite"
)

type Product struct {
gorm.Model
Code string
Price uint
}

func main() {
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}

// Migrate the schema
db.AutoMigrate(&Product{})

// Create
db.Create(&Product{Code: "D42", Price: 100})

// Read
var product Product
db.First(&product, 1) // find product with integer primary key
db.First(&product, "code = ?", "D42") // find product with code D42

// Update - update product's price to 200
db.Model(&product).Update("Price", 200)
// Update - update multiple fields
db.Model(&product).Updates(Product{Price: 200, Code: "F42"}) // non-zero fields
db.Model(&product).Updates(map[string]interface{}{"Price": 200, "Code": "F42"})

// Delete - delete product
db.Delete(&product, 1)
}

References

[1] GORM Guides | GORM - The fantastic ORM library for Golang, aims to be developer friendly. - https://gorm.io/docs/

[2] GORM - The fantastic ORM library for Golang, aims to be developer friendly. - https://gorm.io/

[3] go-gorm/gorm: The fantastic ORM library for Golang, aims to be developer friendly - https://github.com/go-gorm/gorm

[4] gorm · pkg.go.dev - https://pkg.go.dev/gorm.io/gorm

logrus

Logrus is a structured logger for Go (golang), completely API compatible with the standard library logger.

Logrus is in maintenance-mode. We will not be introducing new features. It’s simply too hard to do in a way that won’t break many people’s projects, which is the last thing you want from your Logging library (again…).

Read more »
0%