sublimeÔõôװÖÃgolang
sublimeÊÇÒ»¿îÇáÁ¿¼¶µÄÎı¾±à¼Æ÷£¬¾ßÓÐÇ¿Ê¢µÄ²å¼þϵͳ£¬¿ÉÒÔÖª×ãÖÖÖÖ±à³ÌÓïÑԵĿª·¢ÐèÇó¡£
GolangÊÇÒ»ÖÖÐÂÐ˵ĸßÐÔÄܱà³ÌÓïÑÔ£¬ÒѾ³ÉΪÔÆÅÌËãºÍ´óÊý¾ÝÁìÓòµÄÖ÷Á÷ÓïÑÔÖ®Ò»¡£
ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚSublimeÖÐ×°ÖÃGolang£¬Àû±ãÄú¾ÙÐпª·¢Êµ¼ù¡£
Ò»¡¢×°ÖÃSublime
Ê×ÏÈ£¬ÔÚSublime¹ÙÍøÉÏÏÂÔØÊʺÏÄãµÄ²Ù×÷ϵͳ°æ±¾µÄ×°Öðü£¬È»ºóƾ֤ÌáÐѾÙÐÐ×°Öü´¿É¡£
Á¬Ã¦Ñ§Ï°¡°goÓïÑÔÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¶þ¡¢×°ÖÃGoÓïÑÔ°ü
×°ÖÃGoÓïÑÔ°üÓÐÒÔÏÂÁ½¸ö°ì·¨£º
1.ÏÂÔØGoÓïÑÔ¿ª·¢°ü
ÔÚGolang¹ÙÍøÖУ¬ÏÂÔØÊʺÏÄãµÄ²Ù×÷ϵͳ°æ±¾µÄ¿ª·¢°ü£¬ÏÂÔØÍê³Éºó¾Í¿ÉÒÔƾ֤²Ù×÷ϵͳµÄ×°Ö÷½·¨¾ÙÐÐ×°Öá£
2.ÉèÖÃÇéÐαäÁ¿
ÉèÖÃÇéÐαäÁ¿¿ÉÒÔÈõçÄÔÕÒµ½GoÓïÑÔµÄ×°ÖÃĿ¼£¬½ø¶øʹÓÃGoÓïÑÔ¡£
ÔÚWindowsϵͳÖУ¬¿ÉÒÔƾ֤ÒÔÏ°취¾ÙÐУº
£¨1£©ÔÚ¿ØÖÆÃæ°åÖеã»÷¡°ÏµÍ³ºÍÇå¾²¡±£¬È»ºóµã»÷¡°ÏµÍ³¡±¡£
£¨2£©µã»÷¡°¸ß¼¶ÏµÍ³ÉèÖá±£¬È»ºóµã»÷¡°ÇéÐαäÁ¿¡±¡£
£¨3£©ÔÚ¡°ÏµÍ³±äÁ¿¡±£¨»òÕß¡°Óû§±äÁ¿¡±£©ÖУ¬ÕÒµ½¡°Path¡±±äÁ¿²¢µã»÷¡°±à¼¡±¡£
£¨4£©ÔÚµ¯³öµÄ¡°±à¼ÇéÐαäÁ¿¡±´°¿ÚÖУ¬½«GoÓïÑÔµÄ×°ÖÃĿ¼¼ÓÈëµ½±äÁ¿ÖµÁбíÖС£
£¨5£©ÉèÖÃÍê³Éºó£¬ÐèÒªÖØз¿ªSublimeÈí¼þ²Å»ªÉúЧ¡£
ÔÚMacϵͳÖУ¬¿ÉÒÔƾ֤ÒÔÏ°취¾ÙÐУº
£¨1£©·¿ªTerminal£¨Öնˣ©¡£
£¨2£©ÊäÈëÒÔÏÂÏÂÁ
echo 'export GOROOT=/usr/local/go' >> ~/.bash_profile echo 'export GOPATH=$HOME/Go' >> ~/.bash_profile echo 'export PATH=$PATH:$GOROOT/bin' >> ~/.bash_profile
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬/usr/local/goÌåÏÖGoÓïÑÔµÄ×°ÖÃĿ¼¡£
£¨3£©ÊäÈëÒÔÏÂÏÂÁʹÉèÖÃÉúЧ£º
source ~/.bash_profile
µÇ¼ºó¸´ÖÆ
£¨4£©ÉèÖÃÍê³Éºó£¬ÖØз¿ªSublimeÈí¼þ¼´¿ÉÉúЧ¡£
Èý¡¢×°ÖÃSublime²å¼þ
ÔÚSublimeÖУ¬¿ÉÒÔʹÓÃGoSublimeºÍGo±àÒëÆ÷µÈ²å¼þÀ´Ö§³ÖGolangµÄ¿ª·¢¡£ÕâÀïÎÒÃÇÒÔGoSublimeΪÀý¡£
1.×°ÖÃPackage Control
Package ControlÊÇSublime×Ô´øµÄ²å¼þÖÎÀí¹¤¾ß£¬¿ÉÒÔÀû±ãµØ×°Öá¢Ð¶ÔغÍÖÎÀí²å¼þ¡£
ÔÚSublimeÖУ¬°´Ï¡°ctrl+¡±£¨»òÕß¡°cmd+¡±£©£¬·¿ª¿ØÖÆ̨£¬È»ºóÕ³ÌùÒÔÏ´úÂë²¢»Ø³µ£º
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://packagecontrol.io/' + 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)
µÇ¼ºó¸´ÖÆ
2.×°ÖÃGoSublime
ÔÚSublimeÖУ¬°´Ï¡°ctrl+shift+p¡±£¨»òÕß¡°cmd+shift+p¡±£©£¬·¿ªÏÂÁîÃæ°å£¬ÊäÈë¡°install package¡±²¢»Ø³µ£¬È»ºóÊäÈë¡°GoSublime¡±²¢»Ø³µ¡£
×°ÖÃÍê³Éºó£¬Äã¾Í¿ÉÒÔÔÚSublimeÖÐʹÓÃGoÓïÑÔ¾ÙÐпª·¢ÁË¡£
ËÄ¡¢±àдHello World³ÌÐò
ÔÚÇ°ÃæµÄ°ì·¨ÖУ¬ÎÒÃÇÒѾÍê³ÉÁËSublimeºÍGolangµÄ×°ÖúÍÉèÖã¬ÏÖÔÚÈÃÎÒÃÇÀ´±àдһ¸ö¼òÆÓµÄHello World³ÌÐò¡£
1.½¨ÉèÐÂÎļþ
ÔÚSublimeÖУ¬°´Ï¡°ctrl+n¡±£¨»òÕß¡°cmd+n¡±£©£¬½¨ÉèÒ»¸öÐÂÎļþ¡£
2.ÊäÈë³ÌÐò´úÂë
ÊäÈëÒÔÏ´úÂ룺
package main import "fmt" func main() { fmt.Println("Hello, world!") }
µÇ¼ºó¸´ÖÆ
´úÂë˵Ã÷£º
¸Ã³ÌÐòʹÓÃÁËfmt°ü£¨¼´±ê×¼¿âµÄÃûÌû¯ÊäÈëÊä³ö¿â£©£¬²¢Ê¹ÓÃÆäÖеÄPrintlnÒªÁìÊä³öÒ»ÐÐÎÄ×Ö¡°Hello, world!¡±µ½¿ØÖÆ̨¡£
3.ÉúÑÄÎļþ
ÔÚSublimeÖУ¬°´Ï¡°ctrl+s¡±£¨»òÕß¡°cmd+s¡±£©£¬ÉúÑÄÎļþ£¬²¢½«ÎļþÉúÑĵ½ÄãÉ趨ºÃµÄÊÂÇéĿ¼ÖС£
4.ÔËÐгÌÐò
·¿ªÏÂÁîÐÐÖնˣ¬Çл»µ½³ÌÐòËùÔÚĿ¼£¬È»ºóÊäÈëÒÔÏÂÏÂÁ
go run hello.go
µÇ¼ºó¸´ÖÆ
³ÌÐò½«»áÔÚ¿ØÖÆ̨Êä³ö¡°Hello, world!¡±µÄÐÅÏ¢¡£
µ½ÕâÀÎÒÃǾÍÀֳɵØ×°Öá¢ÉèÖúÍʹÓÃÁËGolangºÍSublime¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú£¬¸ü¶à¹ØÓÚSublimeºÍGolangµÄ½Ì³Ì£¬¾´Çë¹Ø×¢ºóÐøµÄÎÄÕ¡£
ÒÔÉϾÍÊÇsublimeÔõôװÖÃgolangµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡