I wrote a http server using Google's GO Language. However the problem I confronted is not related to the language itself.
I think in certain situations, browsers automatically request favicon.ico as a little icon in the address bar. But my http server fails to properly handle this situation and causes itself to stuck.
It is not the same if I use nc to send request. Simply use "nc IP PORT" to connect, and then:
GET /test.html HTTP/1.0
and hit Enter two times
nc just sends and receives raw data, thus no automatic icon request. So my http server works in such situation with bug in it.
Monday, May 23, 2011
Tuesday, April 12, 2011
Defer, Panic, Recover: New features in GoLang
Defer can push a function call into a LIFO queue, and the function calls in this queue will execute then the surrounding function returns. Defer is perfect for cleaning procedures (like closing files after opening). Arguments are evaluated now, but deferred functions are called later.
Panic will stop the control flow of function and return immediately. Panic will trigger the execution of function calls that are previously deferred.
Wednesday, January 12, 2011
Tuesday, November 23, 2010
Go Language - 函数格式
func (p *myType) save(title string) (*page, os.Error) {
//do something here
p.value := 100
}
1.p *myType。这个类似于C++里的类的用法。save函数是类myType的一个method,在save函数里调用其成员值的时候就使用p.value这样的形式。
2.title string表示函数的参数及其类型。
3.*page, os.Error是函数的返回值。GoLanguage允许多个返回值。
//do something here
p.value := 100
}
1.p *myType。这个类似于C++里的类的用法。save函数是类myType的一个method,在save函数里调用其成员值的时候就使用p.value这样的形式。
2.title string表示函数的参数及其类型。
3.*page, os.Error是函数的返回值。GoLanguage允许多个返回值。
Monday, November 22, 2010
vim配置
配置文件位置
~/.vimrc
syntax on
自动缩进
set cindent
显示行号
set number
记住上次编辑位置
autocmd BufReadPost *\ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif
bash中使用if语句判断字符串是否匹配正则表达式
if [[ $var =~ 正则表达式 ]]; thenecho 'find it'fi
需要注意的是
1.两个[]
2.=~前后都有空格
3.正则表达式形式省略了//
Wednesday, January 13, 2010
Subscribe to:
Posts (Atom)