Configure environment variable
export DATABASE_URL=postgres://postgres@localhost/dbname?sslmode=disable
Run in CLI
go run main.go -page 1
func closer(body io.Closer) { | |
err := body.Close() | |
if err != nil { | |
log.Errorln(err) | |
} | |
} | |
// defer closer(fileDescriptor) |
// https://play.golang.org/p/8SjYn-cisj | |
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io" | |
"os" | |
) |
func execHelper(path, name string, arg ...string) (err error) { | |
cmd := exec.Command(name, arg...) | |
cmd.Dir = path | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
err = cmd.Run() | |
return | |
} |
package helper | |
// closer close descriptor and log error | |
func closer(f io.Closer) { | |
err := f.Close() | |
if err != nil { | |
log.Errorln("closing ", err) | |
} | |
} |
package main | |
import ( | |
"context" | |
"flag" | |
"fmt" | |
"io" | |
"os" | |
"syscall" |
func newFileName() string { | |
buff := make([]byte, 6) | |
rand.Read(buff) | |
return fmt.Sprintf("%v-%X\n", time.Now().UTC().Format("2006-01-02T150405"), buff) | |
} |
Configure environment variable
export DATABASE_URL=postgres://postgres@localhost/dbname?sslmode=disable
Run in CLI
go run main.go -page 1
package strarray | |
import ( | |
"encoding/json" | |
"errors" | |
) | |
var ( | |
// ErrUnsupportedType is returned if the type is not implemented | |
ErrUnsupportedType = errors.New("unsupported type") |
package main | |
import ( | |
"context" | |
"log" | |
"github.com/chromedp/chromedp" | |
) | |
func main() { |
package main | |
import ( | |
"fmt" | |
"net" | |
"net/http" | |
"github.com/gorilla/mux" | |
) |