[go] How to call the class in other package in Go Programming Language

Assume we have two file, of two packages. Here i will use web.go extension to run this example.

 

These two files are located in the same folder.

test.go

package main

import (
"web"
"./user"// Please pay attention here
)

func hello(val
string) string{
return "Hello, world"
}

func main () {
web.Get(
"/(.*)", user.Create)
web.Run(
"0.0.0.0:9999")
}

 

user.go

package user

func Create(val
string) string{
return "create"
}

func Hello(val
string) string{
return "Hello, world"
}

 

The steps to run the app.

1. Compile the user.go first!

8g user.go

 

2. Compile and run the test.go

8g test.go
8l test.
8
.
/8.out

 

Here are two steps you have to be aware of:

A. How to import the user package ==> import ("./user")

B. First compile the user.go!

posted @ 2010-10-25 15:02  DavidHHuan  阅读(494)  评论(0编辑  收藏  举报