Skip to content

Commit

Permalink
fixed bug of multi-line string
Browse files Browse the repository at this point in the history
  • Loading branch information
dlintw committed May 5, 2011
1 parent fd2a9a2 commit 15dd99e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
README.html
*.swp
*.orig
*.[568]
gonetgrep
134 changes: 114 additions & 20 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ This project is just for a sample to show Go's power.
The best method to learn a new language is to try to teach
others. So, this project won't show up a finished code
at once. Intead, I'll keep the my learning experiences
on **Dummy Days** sections and github.com.
on `Dummy Days`_ section of this document and the progress of this program on https://github.com/dlintw/gonetgrep.

BTW, I'm not native English speaker. I'm a newbie of Go.
BTW, I'm not a native English speaker. I'm a newbie of Go.
There are many bugs exist on my code or grammars, please notice me.

This document could be converted to html by docutils, that let the content
could be clickable. See `ReStructuredText`_ for more information.

Usage
^^^^^

Expand All @@ -34,16 +37,28 @@ Dummy Days
^^^^^^^^^^

This is the section of my experience.
I stduy Golang by following methods:

1. Read document_ . (note: the Specification is also must read document)
2. Search question on golang-nuts_.
3. Find similar package on `project dashboard`_ and `packages dashboard`_.
4. Ask question on golang-nuts.

.. _document: http://golang.org/doc/docs.html
.. _golang-nuts: http://groups.google.com/group/golang-nuts
.. _project dashboard: http://godashboard.appspot.com/project
.. _packages dashboard: http://godashboard.appspot.com/package

Day 1
=====
You could check out the source code in different stage. The method is describe
in `Version Control System`_.

Subject: install Go's develop environment
Setup develop environment (cmd:godoc)
=====================================

In fact, I don't like the name of this language.
I would like it named as 'golang' which is more searchable.

I use archlinux. It is easy to install multiple newest packages::
I use archlinux_. It is easy to install multiple newest packages by yaourt_::

yaourt -S go-hg # Google Go

Expand All @@ -54,22 +69,27 @@ I use archlinux. It is easy to install multiple newest packages::
yaourt -S vi vim-diff # my favorite editor
yaourt -S docutils # convert this document into web page form (HTML).

By the way, I suggest to open a github_ account, and learn how to use
git on github. And try to write document in rst_ format.
.. _archlinux: http://www.archlinux.org
.. _yaourt: https://wiki.archlinux.org/index.php/Yaourt

You can read Golang's document without network by::
You can read Golang's document without network by godoc_ ::

godoc -http=:6060 # and launch in browser by http://localhost:6060
godoc godoc # read more usage by this builtin document tool

In fact, if you use brand new version of Go. You should reference package manul by this method instead of just read the offical site's manual. Because official site only keep stable version's package document.

By the way, I suggest to open a github_ account, and learn how to use
git on github. And try to write document in rst_ format.

.. _github: https://github.com
.. _rst: http://docutils.sourceforge.net/docs/user/rst/quickref.html
.. _godoc: http://golang.org/cmd/godoc

Day 2
=====
Suject: compile hello world by Make.inc (cmd:gofmt pkg:flag)
Compile hello world (cmd:gofmt pkg:flag)
========================================

Suject: compile hello world by Make.inc (cmd:gofmt pkg:fmt,flag,os)

Golang provide a **gofmt** utility to make same coding style.
We could try to copy the Makefile from gofmt::
Expand All @@ -81,7 +101,7 @@ We could try to copy the Makefile from gofmt::
cp /opt/go/src/cmd/gofmt/Makefile .

We could reference /opt/go/src/cmd/gofmt/gofmt.go to build our gonetgrep.go.
If gocode installed. Here is the most important tip::
If gocode installed. Here is the most important tip when edit by vim editor::

package main
import "flag" // after declare the flag
Expand All @@ -93,20 +113,94 @@ Press Ctrl-X then Ctrl-O after type **flag.**, you could see flag's members.
If you want to know the usage of member functions, just look godoc.
To clear the automatic typing code, you could try Ctrl-P again.

Question
--------

1. how to write long line string?
Q&A
---

1. How to write long line string in [`fd2a code`_]?

2. 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.
Ans. use back single quote or **+** operator [#ca]_, this bug will cause the
following warning::

time: Wed May 4 06:26:54 ~ 07:33:02 CST 2011
gonetgrep.go:17: syntax error: unexpected semicolon or newline, expecting )

Subjects in the Future


.. _fd2a code: https://github.com/dlintw/gonetgrep/blob/fd2a/gonetgrep.go#L18
.. [#ca] http://groups.google.com/group/golang-nuts/browse_thread/thread/a995c49934392b27
.. code time: Wed May 4 06:26:54 ~ 07:33:02 CST 2011
Appendix
^^^^^^^^

Version Control System
======================

You may see hex deciaml numbers like this [fd2a_].
That's the snapshot of source code at the moment with git version fd2a.

* To read the version's source tree in browser, just click the version.
* To read changes of this version, just click the **commit** on right side
after click the link.
* TO read commit log, click on github's **commit** button on upper bar.

.. _fd2a: https://github.com/dlintw/gonetgrep/tree/fd2a

To check the source code in your linux box, here are sample commands::

# initial copy
git clone git://github.com/dlintw/gonetgrep.git
cd gonetgrep

# get update source
git pull

# show commit log
git log --all
git log # show current checkout version's log only.

# update to special version, for example fd2a
git checkout fd2a

# back to newest version.
git checkout HEAD

# compare the differences of version fd2a and previous version(fd2a^)
git diff fd2a fd2a^

Q&A
----

1. Why 'git ci' can not check in but 'git ci -a' can?

Ans. git's process force you separate a large patch into small pieces by manual add any 'add' or 'modify' patch. [#ga]_

.. [#ga] http://plasmasturm.org/log/gitidxpraise>
ReStructuredText
================

This document is written by ReStructuredText format which is used by python language.

This document could be converted to html by `docutils <http://docutils.sourceforge.net>`_.::
rst2html README.rst README.html

Q&A
---

1. How to hightlight Go's syntax in rst format?


TODO
^^^^

I require help to finish all these jobs. If you can help me. Just fork my source, and notice me to pull your code and document.

* display usage depend on locale
* debug code (pkg:log,runtime)
* read test code of official packages (pkg:testing)
* read file line by line (pkg:io)
* find keyword and display line number (pkg:bytes,regexp)
* get web page (pkg:http)
Expand Down
12 changes: 7 additions & 5 deletions gonetgrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ var gExitCode = 0

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."
)
fmt.Fprintln(os.Stderr, "usage: gonetgrep [flags] <key> url [url...]"+
"\nGrep keyword in multiple web pages.")
flag.PrintDefaults()
os.Exit(2)
}

func main {
func main() {
flag.Parse()
if flag.NArg() < 1 {
usage()
}
println("This is first code Go support utf-8, 也可以用中文寫")
os.Exit(g_exitcode) // go can not return code to shell directly
os.Exit(gExitCode) // go can not return code to shell directly
}

0 comments on commit 15dd99e

Please sign in to comment.