`
sillycat
  • 浏览: 2566828 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Golang(1)Installation and Web Application with Golang

 
阅读更多

Golang(1)Installation and Web Application with Golang

1. Installation
Download the file from here https://go.googlecode.com/files/go1.2.darwin-amd64-osx10.8.tar.gz

Edit the path configuration
>sudo vi ~/.profile
export GOROOT=/opt/go
export PATH=/opt/go/bin:$PATH
>. ~/.profile

Verify the installation
>go version
go version go1.2 darwin/amd64

>vi hello.go
package main

import "fmt"

func main() {  

   fmt.Printf("hello, first installation\n")
}

>go run hello.go
hello, first installation

And few days later, I update the version to 1.2.1.

How to check my System
>uname -m
x86_64

2. Reading Book - Environment
The project is in easygo.

First of all, I create a main class that will be the executable entry for my application.
src/com/sillycat/easygoapp/main.go
package main

import (
     "fmt"
)

func main() {
     fmt.Printf("Hello, sillycat. \n")
}

The I use the command to build the source codes
>go build com/sillycat/easygoapp

This step will generate the binary file in the root directory named easygoapp.
>go install com/sillycat/easygoapp

This will install the binary file into directory
bin/easygoapp

Run the command
>bin/easygoapp 
Hello, sillycat.

And we can also create a function class here
/src/com/sillycat/easygoapp/math/sqrt.go
package math

func Sqrt(x float64) float64 {
     z := 0.0
    for i := 0; i < 1000; i++ {
         z -= (z*z - x) / (2 * x)
    }
    return z
}

Install the function
>go install com/sillycat/easygoapp/math

It will generate the .a file
/Users/carl/work/easy/easygo/pkg/darwin_amd64/com/sillycat/easygoapp/math.a

And the main file will be changed as follow:
package main

import (
     "fmt"
     "math"
)

func main() {
     fmt.Printf("Hello, sillycat. \n")
     fmt.Printf("Math result = %v\n", math.Sqrt(10))
}

3. Go Command
go build
Compile and Test, but for example, the normal package math, if you run the command go build, no file will generate.
Only >go install will generate the .a file.

If it is a main package, it will generate a executable file. Or we can say
>go build -o file path/filename

Default will compile all the .go files under the current directory.

go clean

go fmt

go get

go test
run all the files named like this *_test.go

go list
list all the package under current directory.

go run
>go run src/com/sillycat/easygoapp/main.go 

4. Prepare the IDE
4.1 LiteIDE
https://github.com/visualfc/liteide
I have the go environment, and I download the binary file for MAC

Install gocode
>go get -u github.com/nsf/gocode

Find LiteEnv in the References and set the file darwin64.env
GOROOT=/opt/go
Try to start debug, but I get this Error Message
22:56:53 GdbDebugger: /usr/local/bin/gdb was not found on system PATH (hint: is GDB installed?)
22:56:53 LiteDebug: Failed to start debugger
Solution:
Install GDB
Check my env
>gdb --version
-bash: gdb: command not found

Find the software tool there
http://www.gnu.org/software/gdb/download/
http://ftp.gnu.org/gnu/gdb/

>wget http://ftp.gnu.org/gnu/gdb/gdb-7.7.tar.gz
>tar zxvf gdb-7.7.tar.gz

>./configure --prefix=/Users/carl/tool/gdb-7.7
>make
>sudo make install

>bin/gdb --version
GNU gdb (GDB) 7.7

Soft link the gdb
>sudo ln -s /Users/carl/tool/gdb-7.7 /opt/gdb-7.7
>sudo ln -s /opt/gdb-7.7 /opt/gdb

Find .profile and add
export PATH=/opt/gdb/bin:$PATH

Still do not know how to debug in LiteIDE

4.2 Sublime
sublime + gosublime + gocode + margo

I already have sublime 3. There should be some difference, but most of them should be the same.

Install Package Control
View > Show Console, or use command ‘ctrl’ + `.

Here is the command for sublime text 3.
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

After that, I restart my sublime, and I saw the menu ‘References’ ——> ‘Package Control’, Great, then we can install the plugins we need for sublime 3.

‘Command’ + ’Shift’ + P, or ’Tools’ —> ‘Command Palette’

Type ‘Install Package’ and confirm.

Install ’GoSublime’
Install ’SidebarEnhancements’

Install gocode
>go get -u github.com/nsf/gocode

So it looks great right now.

4.3 Vim
…snip…

4.4 Emacs
…snip...

4.5 Eclipse
…snip…

4.6 IntelliJ IDEA
Find Plugins and install ‘Golang’

Error Message:
Problem with env variables
            GOPATH environment variable is empty or could not be detected properly.
            This means that some tools like go run or go fmt might not run properly.
            See instructions on how to fix this. (show balloon)

Solution:
https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md

>sudo vi /etc/launchd.conf
#limit maxfiles 16384 32768 setenv GOROOT /opt/go setenv GOPATH /Users/carl/work/easy/easygo:/Users/carl/work/go

Hope it works.

References:
http://golang.org/doc/install

Books
http://tour.golang.org/#1
https://github.com/astaxie/build-web-application-with-golang

https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md

Install GDB
http://www.goinggo.net/2013/06/installing-go-gocode-gdb-and-liteide.html

sublime
http://lucifr.com/2011/08/31/sublime-text-2-tricks-and-tips/
https://sublime.wbond.net/installation#ST3

分享到:
评论

相关推荐

    [Go语言入门(含源码)] The Way to Go (with source code)

    Chapter 2—Installation and Runtime Environment............................................................11 2.1 Platforms and architectures.............................................................

    亚信java笔试题-Jianshu-go:简书非官方API,包括用户信息(User)、文章信息(Article)、出版信息(Publicati

    编程语言:golang Installation go get github.com/wuxiaoxiaoshen/jianshu-go 主要的接口包括: User: 个人主页信息 Article : 某篇文章的信息 Home-page: 简书主页的信息 Home-page-recommend: 简书推荐作者的信息...

    The way to go

    Chapter 2—Installation and Runtime Environment............................................................11 2.1 Platforms and architectures.............................................................

    55links友情链接网址跟踪器

    55links友情链接网址跟踪器,放在桌面,每次直接打开就可以访问55links友情链接交易平台,方便快捷。

    [AB PLC例程源码][MMS_046180]CompactFlash Data Storage.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    moore_01_0909.pdf

    moore_01_0909

    FIBR English learning

    FIBR English learning

    [AB PLC例程源码][MMS_042350]How to send-receive SMS text messages using Westermo modem.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    OIF_IEEE802.3_liaison_19OCt09.pdf

    OIF_IEEE802.3_liaison_19OCt09

    SerU,做网络安全FTP内容的实验必备

    做网络安全FTP内容的实验必备

    nagarajan_01_1107.pdf

    nagarajan_01_1107

    [AB PLC例程源码][MMS_043879]Programming in SFC and ST Language.zip

    AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!

    mellitz_3cd_01_0318.pdf

    mellitz_3cd_01_0318

    PyQt6实战派 配套代码

    PyQt6实战派 配套代码

    陕西省省级非物质文化遗产民俗经纬度数据统计表

    陕西省省级非物质文化遗产经纬度数据统计表 统计内容包含以下字段: 1. 项目名称 2. 遗产类别 3. 入选批次 4. 所属地区 5. 申报地区/单位 6. 地理经度 7. 地理纬度 该统计表系统记录了陕西省省级非物质文化遗产的地理空间信息,为文化遗产的数字化保护与研究工作提供了重要的数据支撑。

    ran_3ck_02a_0918.pdf

    ran_3ck_02a_0918

    毕业设计-基于springboot+vue开发的汽车租赁管理系统【源码+sql+可运行】50308.zip

    毕业设计_基于springboot+vue开发的汽车租赁管理系统【源码+sql+可运行】【50308】.zip 全部代码均可运行,亲测可用,尽我所能,为你服务; 1.代码压缩包内容 代码:springboo后端代码+vue前端页面代码; 脚本:数据库SQL脚本 效果图:运行结果请看资源详情效果图 2.环境准备: - JDK1.8+ - maven3.6+ - nodejs14+ - mysql5.6+ - redis 3.技术栈 - 后台:springboot+mybatisPlus+Shiro - 前台:vue+iview+Vuex+Axios - 开发工具: idea、navicate 4.功能列表 - 系统设置:用户管理、角色管理、资源管理、系统日志 - 业务管理:汽车管理、客户管理、租赁订单 3.运行步骤: 步骤一:修改数据库连接信息(ip、port修改) 步骤二:找到启动类xxxApplication启动 4.若不会,可私信博主!!!

    Runcorder - 跑步训练管理系统

    # Runcorder - 跑步训练管理系统 Runcorder 是一款专为跑步爱好者、马拉松运动员及高校体育生设计的本地化跑步训练管理工具,基于 Python 开发,结合 Tkinter 图形界面与强大的数据处理能力,为用户提供从训练记录到数据分析的全方位支持。无论是初学者还是专业跑者,Runcorder 都能帮助你科学规划训练、精准追踪进度,并通过可视化图表直观呈现训练成果,让你的跑步训练更智能、更高效! - **多用户管理**:支持创建、加载和删除用户档案,每个用户的数据独立存储,确保隐私与安全。 - **科学训练记录**:全维度记录跑步数据,包括日期、里程、配速、自评和晨跑标记,支持智能输入校验,避免数据错误。 - **多维数据分析**:通过动态可视化图表展示跑步里程趋势、平均配速曲线,支持自定义 Y 轴范围,帮助用户深入理解训练效果。 - **高阶功能**:提供 4 种科学训练模式(有氧/无氧/混合),支持历史记录修改与删除,数据以 JSON 格式持久化存储,跨平台兼容。

    paatzsch_01_0708.pdf

    paatzsch_01_0708

    开源AI工具下载——AnythingLLMDesktop1.7.3-r2 windows版

    AnythingLLM是一个全栈应用程序,您可以使用流行的开源大语言模型,再结合向量数据库解决方案构建个人本地AI大模型知识库

Global site tag (gtag.js) - Google Analytics