[ANN] gonetgrep - a sample code for learn golang

364 views
Skip to first unread message

dlin

unread,
May 2, 2011, 2:18:51 AM5/2/11
to golang-nuts
I create a project on github.
This project is not my original project, but similar to mine.
I'll try to solve these issues in the project.
I wish get comments and help from friends.
In fact, I'm still learning, but start to write something useful for
this community.

https://github.com/dlintw/gonetgrep

dlin

unread,
May 3, 2011, 7:42:11 PM5/3/11
to golang-nuts
My example project here: https://github.com/dlintw/gonetgrep

My hello world compile failed.

https://github.com/dlintw/gonetgrep/blob/master/gonetgrep.go

how to write long line string?
why 'git ci' can not check in but 'git ci -a' can? I mean why I should
'git add foo' before my 'git ci' even when I just modify them.

Arlen Cuss

unread,
May 3, 2011, 7:51:13 PM5/3/11
to dlin, golang-nuts
2011/5/4 dlin <dlin.tw@gmail.com>
My example project here:  https://github.com/dlintw/gonetgrep

My hello world compile failed.

https://github.com/dlintw/gonetgrep/blob/master/gonetgrep.go

how to write long line string?

Do you mean a string literal that spans multiple lines? Try using back-ticks:

fmt.Fprintf(os.Stderr, `this string
spans
several lines`)
 
why 'git ci' can not check in but 'git ci -a' can? I mean why I should
'git add foo' before my 'git ci' even when I just modify them.

This question doesn't exactly belong here, but the answer is because git uses an index. Here's some information about it. The key points are that you can have several different changes in your working copy at once, and you may want to separate some of those changes into one commit, and some into another. `git add -p` is great for this (give it a try!).

On 5月2日, 下午2時18分, dlin <dlin...@gmail.com> wrote:
> I create a project on github.
> This project is not my original project, but similar to mine.
> I'll try to solve these issues in the project.
> I wish get comments and help from friends.
> In fact, I'm still learning, but start to write something useful for
> this community.
>
> https://github.com/dlintw/gonetgrep



--
Arlen Cuss
Software Engineer
Noble Samurai

Dmitry Chestnykh

unread,
May 3, 2011, 7:57:17 PM5/3/11
to golan...@googlegroups.com
On Wednesday, May 4, 2011 1:42:11 AM UTC+2, dlin wrote:
My example project here:  https://github.com/dlintw/gonetgrep

My hello world compile failed.

https://github.com/dlintw/gonetgrep/blob/master/gonetgrep.go

how to write long line string?

package main

import (
"fmt"
"flag"
"os"
)

// for more command line options example, ref: /opt/go/src/cmd/gofmt/gofmt.go
var IsGrepTable = flag.Int("t", 0, "scan <TABLE>: 0:disable, 1:scan first table, 2:scan 2nd")

func usage() {
// instead of Fprintf, try to use Fprintln, it is easier and powerful
fmt.Fprintln(os.Stderr, "usage: gonetgrep [flags] <key> url [url...]" +
"\nGrep keyword in multiple web pages.")
flag.PrintDefaults()
os.Exit(2)
}

func main() {
flag.Parse()
fmt.Println("This is first code Go support utf-8, 也可以用中文寫")
os.Exit(0) // go can not return code to shell directly
}

 
why 'git ci' can not check in but 'git ci -a' can? I mean why I should
'git add foo' before my 'git ci' even when I just modify them.

peterGo

unread,
May 3, 2011, 8:24:51 PM5/3/11
to golang-nuts
dlin,

The Go language documentation gives you sage advice.

Learning Go

"If you're new to Go, we recommend you work through the tutorial. The
language specification has all the details should you want to
explore."

"Once you've learned a little about the language, Effective Go will
help you learn the style and idioms of programming in Go."

Documentation - The Go Programming Language
http://golang.org/doc/docs.html

In your particular case: "String addition creates a new string by
concatenating the operands." Therefore, you can write:
http://golang.org/doc/go_spec.html#Arithmetic_operators

fmt.Fprintln(os.Stderr, "usage: gonetgrep [flags] <key> url
[url...]" +
"\nGrep keyword in multiple web pages."
)

Don't write it this way with the plus sign on the second line:

fmt.Fprintln(os.Stderr, "usage: gonetgrep [flags] <key> url
[url...]"
+ "\nGrep keyword in multiple web pages."
)

This will fail because of the semicolon rule: “if the newline comes
after a token that could end a statement, add a semicolon”.
http://golang.org/doc/effective_go.html#semicolons

Peter

dlin

unread,
May 3, 2011, 9:08:59 PM5/3/11
to golang-nuts
Peter,

Thank you very much. In fact, I'm not a newbie to Go. I've read
almost all document in golang's site.
I just want to try write a sample code for python/c users.

And both of you provide a good tips for a novice. I'll add your tips
in the sample code.

On 5月4日, 上午8時24分, peterGo <go.peter...@gmail.com> wrote:
> dlin,
>
> The Go language documentation gives you sage advice.
>
> Learning Go
>
> "If you're new to Go, we recommend you work through the tutorial. The
> language specification has all the details should you want to
> explore."
>
> "Once you've learned a little about the language, Effective Go will
> help you learn the style and idioms of programming in Go."
>
> Documentation - The Go Programming Languagehttp://golang.org/doc/docs.html
>
> In your particular case: "String addition creates a new string by
> concatenating the operands." Therefore, you can write:http://golang.org/doc/go_spec.html#Arithmetic_operators
>
>     fmt.Fprintln(os.Stderr, "usage: gonetgrep [flags] <key> url
> [url...]" +
>    "\nGrep keyword in multiple web pages."
>    )
>
> Don't write it this way with the plus sign on the second line:
>
>     fmt.Fprintln(os.Stderr, "usage: gonetgrep [flags] <key> url
> [url...]"
>    + "\nGrep keyword in multiple web pages."
>    )
>
> This will fail because of the semicolon rule: “if the newline comes
> after a token that could end a statement, add a semicolon”.http://golang.org/doc/effective_go.html#semicolons

Dmitry Chestnykh

unread,
May 3, 2011, 9:38:32 PM5/3/11
to golan...@googlegroups.com
On Wednesday, May 4, 2011 3:08:59 AM UTC+2, dlin wrote:
Thank you very much.  In fact, I'm not a newbie to Go.  I've read
almost all document in golang's site.
I just want to try write a sample code for python/c users.

And both of you provide a good tips for a novice.  I'll add your tips
in the sample code.

Aha! We thought you were trying to write some code and can't compile it, so you ask questions here. But you're actually writing a tutorial and this was example questions for Go newbies, and the code was specially crafted to make compiler show errors :-)

Sorry for misunderstanding.

-Dmitry

dlin

unread,
May 4, 2011, 12:02:13 AM5/4/11
to golang-nuts
Yes, these questions are also my questions. I'm very happy to get
help here. Most guys here are friendly even I've asked many stupid
questions.

I'm studying and try to keep my study history on github.
That's will help other newbie to save their time.

In my opinion, the golang's official guide is too 'programming
language designer' style.

I just want to write a tutorial in 'practical' and from the view of C/
Java/Python programmer. I wish to point out what I've learned here.

In fact, this is my plan to learn Go/English/github/rst together.

:)
Reply all
Reply to author
Forward
0 new messages