Пример #1
0
func main() {
	var Book1 Books /* Declare Book1 of type Book */
	var Book2 Books /* Declare Book2 of type Book */

	/* book 1 specification */
	Book1.title = "Go Programming"
	Book1.author = "Mahesh Kumar"
	Book1.subject = "Go Programming Tutorial"
	Book1.book_id = 6495407

	/* book 2 specification */
	Book2.title = "Telecom Billing"
	Book2.author = "Zara Ali"
	Book2.subject = "Telecom Billing Tutorial"
	Book2.book_id = 6495700

	/* print Book1 info */
	fmt.printf("Book 1 title : %s\n", Book1.title)
	fmt.printf("Book 1 author : %s\n", Book1.author)
	fmt.printf("Book 1 subject : %s\n", Book1.subject)
	fmt.printf("Book 1 book_id : %d\n", Book1.book_id)

	/* print Book2 info */
	fmt.printf("Book 2 title : %s\n", Book2.title)
	fmt.printf("Book 2 author : %s\n", Book2.author)
	fmt.printf("Book 2 subject : %s\n", Book2.subject)
	fmt.printf("Book 2 book_id : %d\n", Book2.book_id)
}
Пример #2
0
func (c *controller) createRequest(method string, url string, body []byte) (*http.Request, error) {
	req, err := http.NewRequest(method, url, bytes.NewBuffer(body))
	if err != nil {
		fmt.printf("Unable to create request method=%s url=%s body=%s error=%s\n", method, url, body, err.Error())
		os.Exit(1)
	}
	fmt.Printf("Req created: %s : %s\n\n", req.Method, req.URL)
	return req, nil
}
Пример #3
0
func main() {
	//使用make创建切片len=3,cap=6
	var slice1 = make([]int, 3, 6)
	//使用append给切片增加元素且未超出cap
	slice2 := append(slice1, 1, 2, 3)
	//使用append给切片增加元素并且超出cap
	slice3 := append(slice1, 1, 2, 3, 4)
	fmt.Printf("len=%d cap=%d %v\n", len(slice1), cap(slice1), slice1)
	fmt.Printf("len=%d cap=%d %v\n", len(slice2), cap(slice2), slice2)
	fmt.printf("len=%d cap=%d %v\n", len(slice3), cap(slice3), slice3)
}
Пример #4
0
func main() {
	fmt.printf("hello, world\n")
}
Пример #5
0
func printBook(book *Books) {
	fmt.printf("Book title : %s\n", book.title)
	fmt.printf("Book author : %s\n", book.author)
	fmt.printf("Book subject : %s\n", book.subject)
	fmt.printf("Book book_id : %d\n", book.book_id)
}
Пример #6
0
Файл: cmd.go Проект: zbzzbd/go
func (d  *commandSyncDb)Run() error {
	var drops []string
	if  d.force {
		drops = getDbDropSql(d.al)

	}

	db:=d.al.DB

	if d.force {

		for i,mi :=range modelCache.allordered(){
			query :=drops[i]
			if !d.noInfo {
				fmt.Printf("drop table `%s` \n",mi.table)
			}
			_,err:=db.Exec(query)
			if !d.noInfo {

				fmt.Printf("%s\n",err.Error())
			}





		}
	}
	sqls ,indexs :=getDbCreateSql(d.al)
	tables, err: = d.al.DbBaser.GetTables(db)
	if err != nil {
		if d.rtOnError {
			return err
		}
		fmt.printf("%s\n",err.Error())
	}

	for _,fi :=range fields{
		query :=getColumnAddQuery (d.al,fi)
		if !d.noInfo {
			fmt.Printf("add column `%s`for table `%s` \n",fi.fullName,mi.table)
		}
		_,err :=dbExec(query)
		if err !=nil {
			if d.rtOnError{
				return err 
			}
			fmt.Printf("%s\n",err.Error())
		}
	}

	for _, idx :range indexes[mi.table] {
		if d.al.DbBaser.IndexExists(db,idx.Table,idx.Name) ==false {
			if !d.noInfo{
				fmt.Printf("create index `%s` for table `%s` \n",idx.Name,idx.Table)
			}
			query :=idx.Sql
			_,err :=db.Exec(query)
			if d.verbose {
				fmt.Printf("%s\n",query)
			}
			if err!=nil {
				if d.rtOnError {
					return err
				}
				fmt.Printf("",err.Error())
			}
		}
	}
	continue
}