Skip to content

Instantly share code, notes, and snippets.

@tomcatzh
tomcatzh / readwrite.go
Created April 1, 2015 06:35
Golang readline and writeline
func readLines(path string) ([]string, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
@jpillora
jpillora / smtp-gmail-send.go
Last active March 5, 2024 21:26
Send email using Go (Golang) via GMail with net/smtp
package main
import (
"log"
"net/smtp"
)
func main() {
send("hello there")
}
@madevelopers
madevelopers / readzip.go
Created January 29, 2015 09:36
golang: Read zip file
package main
import (
"archive/zip"
"fmt"
"io/ioutil"
)
type myCloser interface {
Close() error
@francoishill
francoishill / loop_files_folders_recursively.go
Created August 1, 2014 16:52
Loop through files and folders recursively in golang
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() ([]string, error) {
searchDir := "c:/path/to/dir"
@mattetti
mattetti / multipart_upload.go
Last active April 22, 2024 05:24
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
@cespare
cespare / main.go
Created February 20, 2013 03:05
Example of testing Go HTTP servers using httptest.Server.
package main
import (
"log"
"myserver"
"net/http"
)
const addr = "localhost:12345"
@schacon
schacon / gist:942899
Created April 26, 2011 19:19
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete