trygo

package module
v0.0.0-...-2459bba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2019 License: MIT Imports: 43 Imported by: 0

README

trygo

Build Status Go Report Card GoDoc

Simple samples of golang witch goals to covers full feature of golang.

Description

  • testlang.go - Small demos about golang language specification.

  • testlib.go - Small demos about golang standard packages.

  • simtool - Simulate some tools of unix/linux

  • eventframework - A simple event callback framework by golang.

  • cat - A demo impletements the unix-like cat command.

  • demos/.../ - Standalone demos.

Install

sudo apt-get install libgl1-mesa-dev xorg-dev # dependence

go get github.com/quchunguang/trygo
go get github.com/quchunguang/trygo/demos/...

Usage

Demos can be run separatly by testing. For example, we want to run DemoDefine(), we can,

go test -test.run TestDemoDefine

For one of standalone demo named testXXX, run testXXX.

Documentation

Overview

Package trygo implements a simple library demos the package useage..

Index

Constants

View Source
const (
	// Big int
	Big = 1 << 60
	// Small int
	Small = Big >> 59
)
View Source
const (
	// Enone const
	Enone = 1
	// Einval const
	Einval = 2
)
View Source
const (
	CLICK = iota
	DCLICK
	EXIT
	LOAD
	OVER
)

control Application, Yeah!!! Application is control too.

View Source
const (
	ADD
	SUB
	MUL
	DIV
	MAXPOS = 11
)

Some operator

View Source
const Pi = 3.14

Pi math

Variables

View Source
var MorseTable = map[byte]string{
	'A': ".- ",
	'B': "-... ",
	'C': "-.-. ",
	'D': "-.. ",
	'E': ". ",
	'F': "..-. ",
	'G': "--. ",
	'H': ".... ",
	'I': ".. ",
	'J': ".--- ",
	'K': "-.- ",
	'L': ".-.. ",
	'M': "-- ",
	'N': "-. ",
	'O': "--- ",
	'P': ".--. ",
	'Q': "--.- ",
	'R': ".-. ",
	'S': "... ",
	'T': "- ",
	'U': "..- ",
	'V': "...- ",
	'W': ".-- ",
	'X': "-..- ",
	'Y': "-.-- ",
	'Z': "--.. ",
	'0': "----- ",
	'1': ".---- ",
	'2': "..--- ",
	'3': "...-- ",
	'4': "....- ",
	'5': "..... ",
	'6': "-.... ",
	'7': "--... ",
	'8': "---.. ",
	'9': "----. ",
}

MorseTable data

View Source
var MorseTableS = map[byte]string{
	'1': ".- ",
	'2': "..- ",
	'3': "...- ",
	'4': "....- ",
	'5': ". ",
	'6': "-.... ",
	'7': "-... ",
	'8': "-.. ",
	'9': "-. ",
	'0': "- ",
}

MorseTableS data

Functions

func Append

func Append(slice []int, element int) []int

Append func

func Cat

func Cat()

Cat func

func Crawl

func Crawl(url string, depth int, fetcher Fetcher)

Crawl 使用 fetcher 从某个 URL 开始递归的爬取页面,直到达到最大深度。

func DNSLookup

func DNSLookup()

DNSLookup func

func Decode

func Decode(s string) (ret string)

Decode func

func DecodeS

func DecodeS(s string) (ret string)

DecodeS func

func DemoArgs

func DemoArgs()

DemoArgs func

func DemoBase64

func DemoBase64()

DemoBase64 func

func DemoBig

func DemoBig()

DemoBig func

func DemoBinary

func DemoBinary()

func DemoBufio

func DemoBufio()

DemoBufio func

func DemoCalc

func DemoCalc()

DemoCalc func

func DemoChan

func DemoChan()

DemoChan func

func DemoChannel

func DemoChannel()

DemoChannel func

func DemoChannel2

func DemoChannel2()

DemoChannel2 func

func DemoChannel3

func DemoChannel3()

DemoChannel3 func

func DemoChannel4

func DemoChannel4()

DemoChannel4 func

func DemoChannel5

func DemoChannel5()

DemoChannel5 func

func DemoClosure

func DemoClosure()

DemoClosure func

func DemoConst

func DemoConst()

DemoConst func

func DemoCustomtype

func DemoCustomtype()

DemoCustomtype func

func DemoDefer

func DemoDefer()

DemoDefer func

func DemoDefine

func DemoDefine()

DemoDefine func

func DemoDeleteItem

func DemoDeleteItem()

DemoDeleteItem func

func DemoError

func DemoError()

DemoError func

func DemoExec

func DemoExec()

DemoExec func

func DemoExec2

func DemoExec2()

DemoExec2 func

func DemoExec3

func DemoExec3()

DemoExec3 func

func DemoFile

func DemoFile() error

DemoFile func

func DemoFor

func DemoFor()

DemoFor func

func DemoForrange

func DemoForrange()

DemoForrange func

func DemoFunc

func DemoFunc()

DemoFunc func

func DemoFunc2

func DemoFunc2()

DemoFunc2 func

func DemoFuncchan

func DemoFuncchan()

DemoFuncchan func

func DemoFuncvalue

func DemoFuncvalue()

DemoFuncvalue func

func DemoGetenv

func DemoGetenv()

DemoGetenv func

func DemoGoroutine

func DemoGoroutine()

DemoGoroutine func

func DemoGoroutine2

func DemoGoroutine2()

DemoGoroutine2 func

func DemoGoto

func DemoGoto()

DemoGoto func

func DemoHTTP

func DemoHTTP()

DemoHTTP func

func DemoHTTP2

func DemoHTTP2()

DemoHTTP2 func

func DemoHTTPJson

func DemoHTTPJson()

DemoHTTPJson func

func DemoHTTPServ

func DemoHTTPServ()

DemoHTTPServ func

func DemoIf

func DemoIf()

DemoIf func

func DemoImage

func DemoImage()

DemoImage func

func DemoImage2

func DemoImage2()

DemoImage2 func

func DemoImage3

func DemoImage3()

DemoImage3 func

func DemoImage4

func DemoImage4()

DemoImage4 func

func DemoInterface

func DemoInterface()

DemoInterface func

func DemoInterface2

func DemoInterface2()

DemoInterface2 func

func DemoInterface3

func DemoInterface3()

DemoInterface3 func

func DemoInterfaceRecurve

func DemoInterfaceRecurve()

DemoInterfaceRecurve func

func DemoIntrospection

func DemoIntrospection()

DemoIntrospection func

func DemoIo

func DemoIo()

DemoIo func

func DemoIo2

func DemoIo2()

DemoIo2 func

func DemoIo3

func DemoIo3()

DemoIo3 func

func DemoIo4

func DemoIo4()

DemoIo4 func

func DemoJSON

func DemoJSON()

DemoJSON func

func DemoJSON2

func DemoJSON2()

DemoJSON2 func

func DemoJSON3

func DemoJSON3()

DemoJSON3 func

func DemoJSON4

func DemoJSON4()

DemoJSON4 func

func DemoMap

func DemoMap()

DemoMap func

func DemoMap1

func DemoMap1()

DemoMap1 func

func DemoMap2

func DemoMap2()

DemoMap2 func

func DemoMap3

func DemoMap3()

DemoMap3 func

func DemoMethod

func DemoMethod()

DemoMethod func

func DemoMethod2

func DemoMethod2()

DemoMethod2 func

func DemoMime

func DemoMime()

DemoMime func

func DemoMongo

func DemoMongo()

DemoMongo func

func DemoMysql

func DemoMysql()

DemoMysql func

func DemoNet

func DemoNet()

DemoNet func

func DemoPackage

func DemoPackage()

DemoPackage func

func DemoPanic

func DemoPanic()

DemoPanic func

func DemoPipe

func DemoPipe()

DemoPipe func

func DemoPkg

func DemoPkg()

DemoPkg func

func DemoPointer

func DemoPointer()

DemoPointer func

func DemoQueue

func DemoQueue()

DemoQueue func

func DemoRef

func DemoRef()

DemoRef func

func DemoReflect

func DemoReflect()

DemoReflect func

func DemoReflection

func DemoReflection()

DemoReflection func

func DemoReflection2

func DemoReflection2()

DemoReflection2 func

func DemoReflection3

func DemoReflection3()

DemoReflection3 func

func DemoRefs

func DemoRefs()

DemoRefs func

func DemoRegexp

func DemoRegexp()

DemoRegexp func

func DemoRegexp2

func DemoRegexp2()

DemoRegexp2 func

func DemoSendMail

func DemoSendMail()

DemoSendMail func

func DemoSet

func DemoSet()

DemoSet from: github.com/deckarep/golang-set

func DemoSignal

func DemoSignal()

DemoSignal func

func DemoSlice

func DemoSlice()

DemoSlice func

func DemoSlice2

func DemoSlice2()

DemoSlice2 func

func DemoSocket

func DemoSocket()

DemoSocket func

func DemoSort

func DemoSort()

DemoSort func

func DemoSort2

func DemoSort2()

DemoSort2 func

func DemoSortAny

func DemoSortAny()

DemoSortAny func

func DemoSplit

func DemoSplit()

DemoSplit func

func DemoStack

func DemoStack()

DemoStack func

func DemoString

func DemoString()

DemoString func

func DemoStruct

func DemoStruct()

DemoStruct func

func DemoSwitch

func DemoSwitch()

DemoSwitch func

func DemoSync

func DemoSync()

DemoSync func

func DemoSync2

func DemoSync2()

DemoSync2 func

func DemoSync3

func DemoSync3()

DemoSync3 func

func DemoSync4

func DemoSync4()

DemoSync4 func

func DemoTabwriter

func DemoTabwriter()

DemoTabwriter func

func DemoTime

func DemoTime()

DemoTime func

func DemoType

func DemoType()

DemoType func

func DemoType2

func DemoType2()

DemoType2 func

func DemoTypeRecursive

func DemoTypeRecursive()

DemoTypeRecursive func

func DemoVararg2

func DemoVararg2()

DemoVararg2 func

func DemoVarargs

func DemoVarargs()

DemoVarargs func

func DemoXlsx

func DemoXlsx()

DemoXlsx func

func DoubleExtend

func DoubleExtend(slice []int) []int

DoubleExtend func

func DrawLine

func DrawLine(img *image.RGBA, x1, y1, x2, y2 int, color color.Color)

DrawLine func

func Echo

func Echo(c net.Conn)

Echo func

func EchoServer

func EchoServer()

EchoServer func Usage

$ ./test		    # server side
$ nc 127.0.0.1 8053  # client side
abc
abc

true loop by default!

func Encode

func Encode(s string) (ret string)

Encode func

func EncodeS

func EncodeS(s string) (ret string)

EncodeS func

func Even

func Even(i int) bool

Even tests if gaven i is even. Return true for even.

func EventLoop

func EventLoop()

EventLoop framework's main event loop

func ExerciseChecktree

func ExerciseChecktree()

ExerciseChecktree func

func ExerciseCraw

func ExerciseCraw()

ExerciseCraw func

func ExerciseError

func ExerciseError()

ExerciseError func

func ExerciseFibonacci

func ExerciseFibonacci()

ExerciseFibonacci func

func ExerciseFunctions

func ExerciseFunctions()

ExerciseFunctions func

func ExerciseIoreader

func ExerciseIoreader()

ExerciseIoreader func

func ExerciseSqrt

func ExerciseSqrt()

ExerciseSqrt func

func ExerciseWc

func ExerciseWc()

ExerciseWc func

func FakeTime

func FakeTime()

FakeTime func

func Fingerd

func Fingerd()

Fingerd func

func Map

func Map(f func(int) int, l []int) []int

Map func

func Markov

func Markov()

Markov func

func OnclickButton1

func OnclickButton1(c Control)

OnclickButton1 user customized event callback functions

func OnloadApplication

func OnloadApplication(c Control)

OnloadApplication user programming entry OnloadApplication()

func OnloadForm1

func OnloadForm1(c Control)

OnloadForm1 func

func OnoverButton1

func OnoverButton1(c Control)

OnoverButton1 func

func OnoverCheckbox1

func OnoverCheckbox1(c Control)

OnoverCheckbox1 func

func Permrec

func Permrec()

Permrec func

func Psgrp

func Psgrp()

Psgrp func

func SendMail

func SendMail(user, password, host, to, subject, body, mailtype string) error

SendMail func user : example@example.com login smtp server user password: xxxxx login smtp server password host: smtp.example.com:port smtp.163.com:25 to: example@example.com;example1@163.com;example2@sina.com.cn;... subject:The subject of mail body: The content of mail mailtyoe: mail type html or text

func ShowImage

func ShowImage(filename string)

ShowImage using command `display` of ImageMagick

func ShowTag

func ShowTag(i interface{})

ShowTag func

func Sort

func Sort(x Sorter)

Sort sorter

func Sqrt

func Sqrt(x float64) float64

Sqrt func

func SqrtE

func SqrtE(f float64) (float64, error)

SqrtE func

func Uniq

func Uniq()

Uniq func

func Wc

func Wc()

Wc func

Types

type Abser

type Abser interface {
	Abs() float64
}

Abser interface

type AddressBook

type AddressBook struct {
	Name  string
	Phone string
}

AddressBook struct

type Application

type Application struct {
	Text     string
	Objects  map[string]Control
	Bindings map[eventkey]func(Control)
}

Application struct

func (Application) Add

func (a Application) Add(objid string, c Control)

Add target control to application, LOAD event generated either

func (Application) Binding

func (a Application) Binding(objid string, eventid int, op func(Control))

Binding (object, event) with process function

func (Application) Event

func (a Application) Event(objid string, eventid int)

Event process event will cause callback function executed

func (Application) Tostring

func (a Application) Tostring() string

Tostring func

type Blogs

type Blogs struct {
	ID          int
	User        Users
	Title       string
	Description string
	Modified    string
	Published   bool
	Taglist     []string
}

Blogs struct

type Button

type Button struct {
	X    int
	Y    int
	Text string
}

Button struct

func (Button) Tostring

func (b Button) Tostring() string

Tostring func

type ByAge

type ByAge []person

ByAge implements sort.Interface for []person based on the Age field.

func (ByAge) Len

func (a ByAge) Len() int

func (ByAge) Less

func (a ByAge) Less(i, j int) bool

func (ByAge) Swap

func (a ByAge) Swap(i, j int)

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain contains a map ("chain") of prefixes to a list of suffixes. A prefix is a string of prefixLen words joined with spaces. A suffix is a single word. A prefix can have multiple suffixes.

func NewChain

func NewChain(prefixLen int) *Chain

NewChain returns a new Chain with prefixes of prefixLen words.

func (*Chain) Build

func (c *Chain) Build(r io.Reader)

Build reads text from the provided Reader and parses it into prefixes and suffixes that are stored in Chain.

func (*Chain) Generate

func (c *Chain) Generate(n int) string

Generate returns a string of at most n words generated from Chain.

type Checkbox

type Checkbox struct {
	X       int
	Y       int
	Checked bool
}

Checkbox struct

func (Checkbox) Tostring

func (c Checkbox) Tostring() string

Tostring func

type Control

type Control interface {
	Tostring() string
}

Control is the base interface of all control types

type E

type E interface{}

E interface define the empty interface as a type

func Map3

func Map3(n []E, f func(E) E) []E

Map3 func

type ErrNegativeSqrt

type ErrNegativeSqrt float64

ErrNegativeSqrt sorter

func (ErrNegativeSqrt) Error

func (e ErrNegativeSqrt) Error() string

Error func

type Fetcher

type Fetcher interface {
	// Fetch 返回 URL 的 body 内容,并且将在这个页面上找到的 URL 放到一个 slice 中。
	Fetch(url string) (body string, urls []string, err error)
}

Fetcher interface

type Form

type Form struct {
	Width  int
	Height int
	Text   string
}

Form control

func (Form) Tostring

func (f Form) Tostring() string

Tostring func

type Hello

type Hello struct{}

Hello struct

func (Hello) ServeHTTP

func (h Hello) ServeHTTP(w http.ResponseWriter, r *http.Request)

type I

type I interface {
	Get() int
	Put(int)
}

I interface

type Interface1

type Interface1 interface {
	Len(x interface{})
}

Interface1 interface

type Interface2

type Interface2 interface {
	Interface1
	Push(x interface{})
	Pop() interface{}
}

Interface2 interface

type Item

type Item struct {
	Key   string
	Value string
}

Item struct

type MyError

type MyError struct {
	When time.Time
	What string
}

MyError struct

func (*MyError) Error

func (e *MyError) Error() string

type MyFloat

type MyFloat float64

MyFloat type

func (MyFloat) Abs

func (f MyFloat) Abs() float64

Abs func

type MyString

type MyString string

MyString string

type MyStruct

type MyStruct struct {
	// contains filtered or unexported fields
}

MyStruct struct

func (MyStruct) GetName

func (s MyStruct) GetName() string

GetName func

type NameAge

type NameAge struct {
	// contains filtered or unexported fields
}

NameAge struct

type Payload

type Payload struct {
	Blog Blogs
}

Payload struct

type Person

type Person struct {
	Name string `json:"name"` // Tag
	Age  int    `json:"age"`
}

Person struct

type Prefix

type Prefix []string

Prefix is a Markov chain prefix of one or more words.

func (Prefix) Shift

func (p Prefix) Shift(word string)

Shift removes the first word from the Prefix and appends the given word.

func (Prefix) String

func (p Prefix) String() string

String returns the Prefix as a string (for use as a map key).

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue struct

func NewQueue

func NewQueue() *Queue

NewQueue create a new Queue and return.

func (*Queue) Contain

func (q *Queue) Contain(val interface{}) bool

Contain tests if this item in the queue.

func (*Queue) Dequeue

func (q *Queue) Dequeue() *list.Element

Dequeue puts an element out of the queue.

func (*Queue) Enqueue

func (q *Queue) Enqueue(val interface{}) *list.Element

Enqueue puts an element into queue.

func (*Queue) Query

func (q *Queue) Query(queryFunc interface{}) *list.Element

Query returns the element in the queue only if func queueFunc(element) returns true..

func (*Queue) Size

func (q *Queue) Size() int

Size get size of the queue

type R

type R struct {
	// contains filtered or unexported fields
}

R struct

func (*R) Get

func (p *R) Get() int

Get func

func (*R) Put

func (p *R) Put(v int)

Put func

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

ReadWriter interface

type Reader

type Reader interface {
	Read(b []byte) (n int, err error)
}

Reader interface

type S

type S struct {
	// contains filtered or unexported fields
}

S struct

func (*S) Get

func (p *S) Get() int

Get func

func (*S) Put

func (p *S) Put(v int)

Put func

type Score

type Score struct {
	// contains filtered or unexported fields
}

Score struct

type SearchTreeNode

type SearchTreeNode struct {
	Chars    []rune
	Children []*SearchTreeNode
	End      bool
}

func NewSearchTree

func NewSearchTree() *SearchTreeNode

func (*SearchTreeNode) Add

func (n *SearchTreeNode) Add(word string)

func (*SearchTreeNode) Contain

func (n *SearchTreeNode) Contain(word string) (ret bool)

func (*SearchTreeNode) Print

func (n *SearchTreeNode) Print()

type Sorter

type Sorter interface {
	Len() int
	Less(i, j int) bool
	Swap(i, j int)
}

Sorter interface

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack struct

func NewStack

func NewStack() *Stack

NewStack create a new stack.

func (*Stack) Empty

func (stack *Stack) Empty() bool

Empty tests if the stack is empty.

func (*Stack) Len

func (stack *Stack) Len() int

Len get the length of the stack.

func (*Stack) Peak

func (stack *Stack) Peak() interface{}

Peak get the top item of the stack.

func (*Stack) Pop

func (stack *Stack) Pop() interface{}

Pop item from stack.

func (*Stack) Push

func (stack *Stack) Push(value interface{})

Push item to stack.

type SyncedBuffer

type SyncedBuffer struct {
	// contains filtered or unexported fields
}

SyncedBuffer struct

type T

type T struct {
	// contains filtered or unexported fields
}

T struct

type TestMysql

type TestMysql struct {
	// contains filtered or unexported fields
}

TestMysql struct

func Init

func Init() (*TestMysql, error)

Init 初始化数据库引擎

func (*TestMysql) Close

func (test *TestMysql) Close()

Close func

func (*TestMysql) Create

func (test *TestMysql) Create()

Create 测试数据库数据添加

func (*TestMysql) Delete

func (test *TestMysql) Delete()

Delete 测试数据库删除

func (*TestMysql) Read

func (test *TestMysql) Read()

测试数据库数据读取

func (*TestMysql) Update

func (test *TestMysql) Update()

Update 测试数据库数据更新

type Tree

type Tree struct {
	Left  *Tree
	Value int
	Right *Tree
}

Tree struct

type UserDef

type UserDef struct {
	What interface{}
}

UserDef 自定义类型

type Users

type Users struct {
	ID       int
	Name     string
	Username string
}

Users struct

type Vertex

type Vertex struct {
	Lat, Long float64
}

Vertex struct

func (*Vertex) Abs

func (v *Vertex) Abs() float64

Abs func

func (Vertex) NotChange

func (v Vertex) NotChange()

NotChange func

type Writer

type Writer interface {
	Write(b []byte) (n int, err error)
}

Writer interface

type Xi

type Xi []int

Xi for sort

func (Xi) Len

func (p Xi) Len() int

func (Xi) Less

func (p Xi) Less(i int, j int) bool

func (Xi) Swap

func (p Xi) Swap(i int, j int)

type Xs

type Xs []string

Xs for sort

func (Xs) Len

func (p Xs) Len() int

func (Xs) Less

func (p Xs) Less(i int, j int) bool

func (Xs) Swap

func (p Xs) Swap(i int, j int)

Directories

Path Synopsis
demos
demo_algorithms
3.7 Bernoulli test A test throw corn N times, see how many times gets the front side.
3.7 Bernoulli test A test throw corn N times, see how many times gets the front side.
demo_closure_recursion
Closure recursion
Closure recursion
demo_map
https://blog.golang.org/go-maps-in-action
https://blog.golang.org/go-maps-in-action
demo_pg
Manuals ======= Install DB ---------- pi@host$ sudo apt-get install postgresql Create database and its account ------------------------------- Notice: user/password must match exist accounts in OS !!! pi@host$ sudo -u postgres psql -U postgres CREATE USER pi WITH PASSWORD 'xxxxxx'; CREATE DATABASE snsrobot; GRANT ALL PRIVILEGES ON DATABASE snsrobot TO pi; \q # raspbian with raspberry pi 2: pi@host$ sudo -u postgres cat <<_END >>/var/lib/postgresql/data/pg_hba.conf # ubuntu: pi@host$ #sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/pg_hba.conf host all "pi" 0.0.0.0/0 trust _END pi@host$ sudo service postgresql restart Create tables in host --------------------- pi@host$ psql snsrobot snsrobot => CREATE TABLE userinfo ( uid serial NOT NULL, username character varying(100) NOT NULL, departname character varying(500) NOT NULL, Created date, CONSTRAINT userinfo_pkey PRIMARY KEY (uid) ) WITH (OIDS=FALSE); snsrobot => \q Configure the remote access --------------------------- pi@host$ sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/postgresql.conf listen_addresses='*' _END pi@host$ sudo service postgresql restart user@client$ psql -h 192.168.1.109 -U pi -W -d snsrobot Usage Example ------------- user@client$ go build user@client$ ./testpg.exe -c pi:xxxxx@192.168.1.109/snsrobot [Demo program]: http://astaxie.gitbooks.io/build-web-application-with-golang/content/en/05.4.html [Remote access]: http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html
Manuals ======= Install DB ---------- pi@host$ sudo apt-get install postgresql Create database and its account ------------------------------- Notice: user/password must match exist accounts in OS !!! pi@host$ sudo -u postgres psql -U postgres CREATE USER pi WITH PASSWORD 'xxxxxx'; CREATE DATABASE snsrobot; GRANT ALL PRIVILEGES ON DATABASE snsrobot TO pi; \q # raspbian with raspberry pi 2: pi@host$ sudo -u postgres cat <<_END >>/var/lib/postgresql/data/pg_hba.conf # ubuntu: pi@host$ #sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/pg_hba.conf host all "pi" 0.0.0.0/0 trust _END pi@host$ sudo service postgresql restart Create tables in host --------------------- pi@host$ psql snsrobot snsrobot => CREATE TABLE userinfo ( uid serial NOT NULL, username character varying(100) NOT NULL, departname character varying(500) NOT NULL, Created date, CONSTRAINT userinfo_pkey PRIMARY KEY (uid) ) WITH (OIDS=FALSE); snsrobot => \q Configure the remote access --------------------------- pi@host$ sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/postgresql.conf listen_addresses='*' _END pi@host$ sudo service postgresql restart user@client$ psql -h 192.168.1.109 -U pi -W -d snsrobot Usage Example ------------- user@client$ go build user@client$ ./testpg.exe -c pi:xxxxx@192.168.1.109/snsrobot [Demo program]: http://astaxie.gitbooks.io/build-web-application-with-golang/content/en/05.4.html [Remote access]: http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html
demo_pg_json
Manuals ======= Install DB ---------- pi@host$ sudo apt-get install postgresql Create database and its account ------------------------------- Notice: user/password must match exist accounts in OS !!! pi@host$ sudo -u postgres psql -U postgres CREATE USER pi WITH PASSWORD 'xxxxxx'; CREATE DATABASE snsrobot; GRANT ALL PRIVILEGES ON DATABASE snsrobot TO pi; \q # raspbian with raspberry pi 2: pi@host$ sudo -u postgres cat <<_END >>/var/lib/postgresql/data/pg_hba.conf # ubuntu: pi@host$ #sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/pg_hba.conf host all "pi" 0.0.0.0/0 trust _END pi@host$ sudo service postgresql restart Create tables in host --------------------- pi@host$ psql snsrobot snsrobot => CREATE TABLE userinfo ( uid serial NOT NULL, username character varying(100) NOT NULL, departname character varying(500) NOT NULL, Created date, CONSTRAINT userinfo_pkey PRIMARY KEY (uid) ) WITH (OIDS=FALSE); snsrobot => \q Configure the remote access --------------------------- pi@host$ sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/postgresql.conf listen_addresses='*' _END pi@host$ sudo service postgresql restart user@client$ psql -h 192.168.1.109 -U pi -W -d snsrobot Usage Example ------------- user@client$ go build user@client$ ./testpg.exe -c pi:xxxxx@192.168.1.109/snsrobot [Demo program]: http://astaxie.gitbooks.io/build-web-application-with-golang/content/en/05.4.html [Remote access]: http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html
Manuals ======= Install DB ---------- pi@host$ sudo apt-get install postgresql Create database and its account ------------------------------- Notice: user/password must match exist accounts in OS !!! pi@host$ sudo -u postgres psql -U postgres CREATE USER pi WITH PASSWORD 'xxxxxx'; CREATE DATABASE snsrobot; GRANT ALL PRIVILEGES ON DATABASE snsrobot TO pi; \q # raspbian with raspberry pi 2: pi@host$ sudo -u postgres cat <<_END >>/var/lib/postgresql/data/pg_hba.conf # ubuntu: pi@host$ #sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/pg_hba.conf host all "pi" 0.0.0.0/0 trust _END pi@host$ sudo service postgresql restart Create tables in host --------------------- pi@host$ psql snsrobot snsrobot => CREATE TABLE userinfo ( uid serial NOT NULL, username character varying(100) NOT NULL, departname character varying(500) NOT NULL, Created date, CONSTRAINT userinfo_pkey PRIMARY KEY (uid) ) WITH (OIDS=FALSE); snsrobot => \q Configure the remote access --------------------------- pi@host$ sudo -u postgres cat <<_END >>/etc/postgresql/9.4/main/postgresql.conf listen_addresses='*' _END pi@host$ sudo service postgresql restart user@client$ psql -h 192.168.1.109 -U pi -W -d snsrobot Usage Example ------------- user@client$ go build user@client$ ./testpg.exe -c pi:xxxxx@192.168.1.109/snsrobot [Demo program]: http://astaxie.gitbooks.io/build-web-application-with-golang/content/en/05.4.html [Remote access]: http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html
demo_redis
Demon for manage connection pool of redis.
Demon for manage connection pool of redis.
demo_runtemplate
Install `runtemplate` by `go get github.com/flowonyx/runtemplate`.
Install `runtemplate` by `go get github.com/flowonyx/runtemplate`.
demo_service
simple does nothing except block while running the service.
simple does nothing except block while running the service.
demo_tmp
http://blog.studygolang.com/2013/01/go%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86%E4%B9%8Brsa/ 密钥长度,1024觉得不够安全的话可以用2048,但是代价也相应增大 openssl genrsa -out private.pem 1024 用于生成密钥。
http://blog.studygolang.com/2013/01/go%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86%E4%B9%8Brsa/ 密钥长度,1024觉得不够安全的话可以用2048,但是代价也相应增大 openssl genrsa -out private.pem 1024 用于生成密钥。
tools
try

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL