人çã®äŸã§æ°ããèšèªã«ç²Ÿéããã®ãæã楜ããã®ã§ãããããããšãªããç§ã¯ã人çãããæãåªå 床ã®é«ããã«åºäŒã£ãæåã®ã¿ã¹ã¯ãåããŸããã
ã€ã³ã¿ãŒãããhttp://vpustotu.ruã«ã¯ ã誰ã§ãèŠçã«ã€ããŠå¿åã§è©±ãããšãã§ãããµã€ãããããŸãã ãã¹ãŠã®ã¹ããŒãã¡ã³ãïŒå°æ¥çã«ã¯ãåŒçšããšåŒã³ãŸãïŒã¯ãŸãã¢ãã¬ãŒã·ã§ã³ïŒãã·ã§ã«ã°ã®ãæ·±âãã«é¡äŒŒïŒã«åé¡ãããŸãã ã¢ãã¬ãŒãããŒãžïŒ http://vpustotu.ru/moderation/ ïŒã«ã¯ãã©ã³ãã ãªåŒçšãæ祚ãªã³ã¯ãããã³åãããŒãžã«ã€ãªããããã®ä»ããªã³ã¯ã衚瀺ãããŸãã ã¯ãªãã¯ãããã¯ãã¹ãŠéåžžã«ç°¡åã§ãã
ãããŠãã¿ã¹ã¯ãçºçããŸãã -ç·æ¥ã«ãæéã®äžã§ããããªãç§å¯ã®ç 究ã®ããã«ç¯åºŠã«é¢ãããã¹ãŠã®åŒçšã®å®å šãªãã³ããã¢ããããŒãããå¿ èŠããããŸããã ã¿ã¹ã¯ã®äžä¿çãªäŸ¡å€ãçœçŽã®çšåºŠã¯è©äŸ¡ããŸããããæè¡çãªèŠ³ç¹ããæ€èšããŸãã
ã¢ãã¬ãŒãã»ã¯ã·ã§ã³ã«ã¯ç¹å®ã®èŠç©ãããžã®çŽæ¥ãªã³ã¯ã¯ãããŸãããæ°ããèŠç©ãããååŸããå¯äžã®æ¹æ³ã¯ãããŒãžãæŽæ°ããããšã§ãïŒãŸãã¯ãã詳现ããªã³ã¯ãã¯ãªãã¯ããŸãïŒã ããã«ãç¹°ãè¿ãã¯ããªãå¯èœã§ããããã¯ãæ°åéã®ç©æ¥µçãªã¯ãªãã¯ã®åŸãç°¡åã«æ€åºãããŸãã
ãããã£ãŠã次ã®ããã°ã©ã ãå¿ èŠã§ãã
- äžè²«ããŠããŒãžãæŽæ°ããã³è§£æïŒè§£æïŒããåŒçšãæžãçããŸãã
- éè€ãç Žæ£ã§ããå¿ èŠããããŸãã
ãã¹ãŠã®åŒçšç¬Šãèªã¿èŸŒãŸããŠãããã©ããããããªãã®ã¯è«ççã§ãããããã¯ãé£ç¶ããŠç¹°ãè¿ãåä¿¡ãããå€æ°ã®åŒçšç¬Šã«ãã£ãŠéæ¥çã«æšæž¬ã§ããŸãã ãããã£ãŠã以äžãè£è¶³ããŸãã
- ã³ãã³ãã§åæ¢ããã ãã§ãªããäžå®æ°ã®ãç¹°ãè¿ãããããšãã°500ã«éãããšåæ¢ããŸãã
- ããã«ã¯æéããããå¯èœæ§ãé«ããããçµäºåŸã«ãäžæãããšãããããç¶è¡ã§ããå¿ èŠããããŸãã
- ãŸããããã¯ãŸã é·ãã®ã§ãããã€ãã®ã¹ããªãŒã ã§æ±ãä»äºããããŠãã ããã ãŸããããã¯4ã¹ã¬ããïŒãŸãã¯5ã¹ã¬ããïŒã«ããªããŸãã
- ãããŠãæåããããšããããšãã°10ç§ããšã«ã³ã³ãœãŒã«ã«å ±åããŸãã
- ãããŠãã³ãã³ãã©ã€ã³åŒæ°ããããããã¹ãŠã®ãã©ã¡ãŒã¿ãŒãåãå ¥ããããŸãïŒ
ãŸãããã¹ãŠãæãããªããã§ãã ããã°ã©ã ã2ã€ã®ãã¡ã€ã«ãä¿æããããã«ããŸã-åŒçšç¬Šãšãããã®åŒçšç¬Šã®ããã·ã¥ã䜿çšããŠãç¹°ãè¿ããªãããã«ããåå®è¡ã®éå§æã«ãã¡ã€ã«ãåèªã¿èŸŒã¿ããŸãã ããã§ã¯ãé¡ã§ctrl-cãåãåãããäžå®ã®ç¹°ãè¿ãåæ°ã«æºããªããªããŸã§ããµã€ã¯ã«ã§åœŒã¯ããŒãžã解æãããŸããŸãå€ãã®å瀺ãåŒãåºããŸãã ã¿ã¹ã¯ã¯æ確ã§ãèšç»ããããŸã-è¡ããïŒ
ãæ°ã«å ¥ãã®ãšãã£ã¿ãŒãéããæ°ãããããžã§ã¯ããäœæããŸãã æåã¯ã空ã®ããã°ã©ã ã®ã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
package main import ( "fmt" ) func main() { fmt.Println("Hello World!") }
ç§ãã¡ã¯ããã°ã©ã ã®é çªã§ãªã¹ãã調ã¹å§ããŸãïŒ
ãã¹ããªãŒã ãã®æ°ããã¡ã€ã«åãªã©ãããã€ãã®ãã©ã¡ãŒã¿ãŒããããŸãã çµã¿èŸŒã¿ã®ã flag ãããã±ãŒãžã¯ãã³ãã³ãã©ã€ã³ãããã®ãã¹ãŠã®çŸãããåŒãåºãã®ã«åœ¹ç«ã¡ãŸãã ã€ã³ããŒããªã¹ãã«è¿œå ããåæã«ãã©ã¡ãŒã¿ãŒå€æ°ã宣èšããŸãã
import ( "flag" "fmt" ) var ( WORKERS int = 2 //- "" REPORT_PERIOD int = 10 // () DUP_TO_STOP int = 500 // HASH_FILE string = "hash.bin" // QUOTES_FILE string = "quotes.txt" // )
Goã®å€æ°ã®åã¯ãã®ååã®åŸã«èšè¿°ãããŸãããããã¯å°ãçããå ŽåããããŸãã ãŸãããã¹ãŠã䟿å©ã§äžç®æã«åãŸãããã«ãããã©ã«ãå€ãããã«åæåããŸãã
åŒæ°ã®è§£æãªã©ã¯éåžžinitïŒïŒé¢æ°ã§è¡ãããŸãã
func init() { // : flag.IntVar(&WORKERS, "w", WORKERS, " ") flag.IntVar(&REPORT_PERIOD, "r", REPORT_PERIOD, " ()") flag.IntVar(&DUP_TO_STOP, "d", DUP_TO_STOP, "- ") flag.StringVar(&HASH_FILE, "hf", HASH_FILE, " ") flag.StringVar("ES_FILE, "qf", QUOTES_FILE, " ") // flag.Parse() }
UPDïŒ ã³ã¡ã³ã㧠Forked Habraiserã¯ãinitã§flag.ParseïŒïŒé¢æ°ãåŒã³åºãã®ãæªãç¿æ £ã§ããçç±ãäžè¬çã«èª¬æããŸããã 圌ã«æè¬ããŸã-ããããmainïŒïŒã§ãããè¡ãããšããå§ãããŸããããã®äŸã¯ãfu do thisïŒããšããæèšãšããŠããã«æ®ããŸãã
ãã©ã°ããã±ãŒãžã®é¢æ°IntVar ïŒæ°å€çšïŒããã³StringVar ïŒæååçšïŒã䜿çšããŸã-ã³ãã³ãã©ã€ã³åŒæ°ããæå®ãããããŒãèªã¿åããå€æ°ã«æž¡ããŸãã ããŒãæå®ãããŠããªãå Žåãããã©ã«ãå€ã䜿çšãããŸãã é¢æ°ã®æ§æã¯åãã§ãïŒ
flag.StringVar( &_, . , , )
é¢æ°ãå¿ èŠã«å¿ããŠå€æŽã§ããããã«ãå€æ°ïŒïŒèšå·ïŒã«ãã€ã³ã¿ãŒãæž¡ãããšã«æ³šæããŠãã ããã ãã©ã¡ãŒã¿ãããŒã®èª¬æããèå³æ·±ãã§ããå®éã«ã¯ããã©ã°ããã±ãŒãžã¯ã-hãããŒã§ã¢ã¯ã»ã¹å¯èœãªåŒæ°ã®å¡äŸãèªåçã«äœæããŸãã ä»ããããã°ã©ã ãèµ·åããŠããããèŠãããšãã§ããŸãïŒ
C:\Go\src\habratest>habratest.exe -h Usage of habratest.exe: -d=500: - -hf="hash.bin": -qf="quotes.txt": -r=10: () -w=2:
ããã«ãèšç»ã«ãããšãããã°ã©ã ã®èµ·åæã«ããã·ã¥ãããŒããããŸãããåŸã§ããŒããããã®ããããšãã«ããã«æ»ãããšããå§ãããŸãã ä»ã®ãšããããã¹ãŠã®èµ·åãæåã§ããããšãæ³åããŠãã ããã
次ã«ãããã°ã©ã èªäœã«ã€ããŠèããŠã¿ãŸããããããŒãžãèªã¿åãããããå解ããçµæãèšé²ããé²è¡ç¶æ³ãåæããå¿ èŠããããŸãã ã¯ãããããŠããã€ãã®ãã¹ã¬ãããã§ïŒããã«å€æããŸã-ã¹ã¬ããã§ã¯ãªãã¹ã¬ãããšåŒã³ãŸãããŸãã念ã®ããïŒã ãïŒ
Goã®ãã«ãã¿ã¹ã¯ã¯goroutinesã«ãã£ãŠå®è£ ãããŸããã€ãŸãããã®åã«ãããgoãããŒã¯ãŒãã眮æããããšã«ããããããã¯ã°ã©ãŠã³ããã§ä»»æã®é¢æ°ãå®è¡ã§ããŸããããã¯éå§ããããã°ã©ã ã¯ããã«ç¶è¡ããŸããããã«å¥ã®ããšãã§ããŸãïŒ
// ... func GadgetUmbrella() { //... ... } //... , : go GadgetUmbrella() fmt.Println(" !") // , GadgetUmbrella()
äžè¬ã«ããŽã«ãã³ã¯çŽç²ãªã¹ããªãŒã ã§ã¯ãªãããã¹ãŠãããèå³æ·±ããã®ã§ããããã®ãããªããšã¯æããã«ç§ãã¡ã®å²ãåœãŠã®ç¯å²ãè¶ ããŠããŸãã
ç¡éã«ãŒãã§ããŒãžãèªã¿èŸŒãã§è§£æããå®æããåŒçšãäžããé¢æ°ãå¥ã®ãã¹ããªãŒã ãã«å ¥ããããšãææ¡ããŸããããããã°ã©ããŒããšåŒã³ãŸãããã ããã€ãã®ã³ããŒã§ããã¯ã°ã©ãŠã³ãã§èªåèªèº«ãå転ãããŠãã ãããã¡ã€ã³ããã°ã©ã ããç§ãã¡ã¯ãããã®åŒçšããµã€ã¯ã«ã§ãã£ãããããããã䜿çšããŠå¿ èŠãªããšãè¡ããç¹å®ã®ç¶æ³ã®å Žåã«ã¯äœæ¥ããªãã«ããŸãã ç¹ã«ããã§ã«ãã«ãã¹ã¬ããããã°ã©ãã³ã°ã®çµéšããããå ±æãšåæã®å€ãã®ãã¥ã¢ã³ã¹ã«ã€ããŠææã§æ²é³Žãäžããæºåãã§ããŠãã人ã«ãšã£ãŠã¯ãçãããã»ã©ç°¡åã«èãããŸãã
ãããå®éã«ã¯ãGoã®ãã1ã€ã®åªããæ©èœã¯ãã£ã³ãã«ã§ããããããã¹ãŠãæ¬åœã«ã·ã³ãã«ã§ãã ç°¡åã«èšãã°ããã£ãã«ã¯ãäžæ¹ã®åŽã§å€ãã¹ããŒãããããäžæ¹ã®åŽã§ãã£ããããããã€ããšããŠç°¡åã«æ³åã§ããŸãã ãã£ã³ãã«ã¯å žåçãªãã®ã§ãããåæåãå¿ èŠã§ã-ç°¡åã«æ¬¡ã®ããã«æäœããŸãïŒ
func send( c chan int) { <- 15 // } func main() { ch := make(chan int) // (int) go send(ch) b:= <-ch // fmt.Println(b) }
ç§ã¯goïŒchïŒãæžããã ãã§ãªããïŒshïŒãæžããããšã«æ³šæããŠãã ããã å®éã«ã¯ãããã©ã«ãã§ã¯ããã£ãã«ããã®ããŒã¿ã®éä¿¡ãšåä¿¡ã¯ãããäžæ¹ã®ç«¯ãããŒã¿ãåŠçããæºåãã§ãããŸã§ãããããåŒãèµ·ããããµãã«ãŒãã³ããããã¯ããŸãã ããã¯éåžžã«åªããåæããŒã«ã§ãã
ã go ããåé€ãããšã sendïŒïŒãã¡ã€ã³ã¹ã¬ããã§å®è¡ããããããã¯ãããŸããããã¯ã誰ãã15çªãããã¯ã¢ããããæºåãã§ãããŸã§åŸ æ©ããããã§ãã次ã®è¡ã§ããã¯ã¢ããããŸãããå¶åŸ¡ã移ããŸããã ãããããã¯ã誰ããæ²ããã
ãã ããã go sendïŒïŒ ãã®å Žåã sendïŒïŒã¯ãããã¯ãããŸãããã¹ããªãŒã å ã§ãå¥ã®èªã¿åããè¡ããŸã§åŸ æ©ããããããã¹ãŠãã¹ã ãŒãºã«å®è¡ãããŸã -ããã¯ããã«è¡ãããããŒã¿äº€æãè¡ãããŸãæåããŸããã
ãŸãã sendïŒïŒé¢æ°ã§ãã£ãã«ãžã®æžã蟌ã¿ãåé€ãããšã bïŒ= <-cè¡ã®ã¡ã€ã³é¢æ°ã¯ãåä¿¡ãããã®ããªããããéã«ç¡å¹ã«ãªããŸãã
ãã£ã³ãã«ã¯ãããããã¡ãŒã¹ãã¯ã©ã¹ã®ãªããžã§ã¯ãã§ããã䟿å©ãªããã«äœæã転éãè¿åŽãå²ãåœãŠãå¯èœã§ãã
ããŒã¿ã¯ãã°ã©ããŒããšããŠéä¿¡ãããã¡ã€ã³ãµã€ã¯ã«ã§åä¿¡ãããŸãã
ããŒãžã³ãŒãå ã®åŒçšã¯ãåã«ã¯ã©ã¹ãfi_textããæã€divã«ãããŸãã ãã°ã©ããŒãã§ååŸããã«ã¯ã goqueryããã±ãŒãžã䜿çšããŸããããã«ãããhtmlããŒãžã解æããjQueryã®ã»ã¬ã¯ã¿ãŒã䜿çšããŠãã®ã³ã³ãã³ãã«ã¢ã¯ã»ã¹ã§ããŸãã ãã®ããã±ãŒãžã¯æšæºããã±ãŒãžã«ã¯å«ãŸããŠããªããããæåã«ã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
# : go get github.com/opesun/goquery
ãŸããã³ãŒãã®ã€ã³ããŒãã»ã¯ã·ã§ã³ã«ãããã±ãŒãžãgithub.com/opesun/goqueryãããstringsãããtimeããè¿œå ããŸããé 延ã®ããã«åŸè ãå¿ èŠã§ãããªã¯ãšã¹ãã§ãµãŒããŒãåžžã«ãã«ããããã§ã¯ãããŸããïŒãããããããããªãã¯ç§ãç解ããŠããŸãïŒïŒ
import ( "flag" "fmt" "github.com/opesun/goquery" "strings" "time" )
ãã€ã³ãã«è¿ã¥ããŠããã°ã©ããŒãã³ãŒããèšè¿°ããŸãã
func grab() <-chan string { // , string c := make(chan string) for i := 0; i < WORKERS; i++ { // - worker'o go func() { for { // x, err := goquery.ParseUrl("http://vpustotu.ru/moderation/") if err == nil { if s := strings.TrimSpace(x.Find(".fi_text").Text()); s != "" { c <- s // } } time.Sleep(100 * time.Millisecond) } }() } fmt.Println(" : ", WORKERS) return c }
ã³ãŒãã¯éåžžã«ã·ã³ãã«ã§ãã³ã¡ã³ãã¯ã»ãšãã©å¿ èŠãããŸããã
ã¯ããŒãžã£ãŒã䜿çšããŠã grabïŒïŒã«ãã£ãŠè¿ããããã£ãã«ã«ããŒã¿ãåžžã«éä¿¡ããå¿åé¢æ°ãå®è¡ããå¿ èŠãªæ°ã®gourutinãäœæããŸãã ãã®ãããªãã¿ãŒã³ã¯ãžã§ãã¬ãŒã¿ãŒãšåŒã°ããŸãã
äœããã®çç±ã§ã x.FindïŒ "ãFi_text"ïŒãTextïŒïŒã¯ãå é ãšæ«å°Ÿã«ã¹ããŒã¹ãããç®çã®èŠçŽ ã®ã³ã³ãã³ããè¿ããã®ã§ãããããããšãªããæšæºã®æååã¢ãžã¥ãŒã«ã®TrimSpaceé¢æ°ã§ã¯ãªã¢ããŸãã
ãžã§ãã¬ãŒã¿ãŒã®æºåãã§ããã®ã§ãmainïŒïŒé¢æ°ãå€æŽããããšã§ããžã§ãã¬ãŒã¿ãŒãæ©èœããããšã確èªã§ããŸãã
func main() { quote_chan := grab() for i := 0; i < 5; i++ { // 5 fmt.Println(<-quote_chan, "\n") } }
èšç»éãã«ãã¹ãŠãé²ãã§ããããšãããããŸããå瀺ãç§ãã¡ã®ãã£ã³ãã«ã«åºç¯ã«æµã蟌ãã§ããŸãïŒ
次ã«ãèšç»ã«åŸã£ãŠå€ãåéããã¡ã€ã³ãµã€ã¯ã«ã«ã€ããŠèããŠã¿ãŸãããã èŠä»¶ãšèŠæã«å¿ããŠã次ã®ãµã€ã¯ã«ãå¿ èŠã§ãã
- åŒçšãåéããŸãã
- ããã·ã¥åŒçšç¬Šãšæ¢åã®åŒçšç¬Šãæ¯èŒããŠãäžææ§ã確èªããŸã
- æ°ããåŒçšã®å Žåã«åŒçšãšããã·ã¥ããã¡ã€ã«ã«ä¿åããŸã
- è¡ã®ç¹°ãè¿ãæ°ãç£èŠããŸã
- REPORT_PERIODç§ããšã«å ±åãã
- ã«ãŒãã¯ç¡éã§ãããããctrl-cããã£ããããŠããŠãŒã¶ãŒã®ã³ãã³ãã§æ£ããçµäºããŸãã
ã³ã¬ã¯ã·ã§ã³ã«é¢ããåé¡ã¯ãããããŸãããããã·ã¥ã決å®ããŸãã
ç°¡åã«ããããã«ãåŒçšããmd5ãååŸããããšããå§ãããŸãã ããã·ã¥ãããã ïŒããŒãšå€ã®ã¹ãã¬ãŒãžã®çµã¿èŸŒã¿æ§é ïŒã«ä¿åããã®ã§ããã°ããç°¡åã«æ€çŽ¢ã§ããŸãã äžææ§ããã§ãã¯ããçµ±èšãšç¹°ãè¿ããã«ãŠã³ãããŸã-ããã¯æè¡ã®åé¡ã§ãã Goã§ãã¡ã€ã«ãæäœããããšã¯ä»ã®èšèªãšå€ãããªããããåé¡ããããŸããã
æéã¬ããŒãã¯ãæšæºã®ã æé ãããã±ãŒãžã®ãã£ãã«ãŒã䜿çšããŠå®è£ ã§ããŸãã ããã¯ãæå®ãããæéåŸã«ããªã¬ãŒãããç¹å®ã®å€ããã£ãã«ã«éä¿¡ããæãåçŽãªã¿ã€ããŒã§ããããŒã¿ãåä¿¡ãããšããã£ãã«ãç£èŠããŠçµ±èšã衚瀺ããã ãã§ãã
ãããŠãã os / signal ãããã±ãŒãžã䜿çšããŠã³ãã³ããå®äºãããããã«ãã£ããããŸããããã«ãããã€ãã³ãéç¥ããã£ãã«ã«éä¿¡ããç¹å®ã®ã·ã°ãã«ã«éç¥æ©èœãæããããšãã§ããŸãã
èšç»ã¯æºåãæŽã£ãŠããŸããã1ã€ã®èŠåããããŸãïŒããŒã¿ãåä¿¡ãã3ã€ã®ç°ãªããã£ãã«ãååŸããŸããã以åã¯èªã¿åããåŸ æ©ããŠããéãã¹ããªãŒã ããããã¯ããããããäžåºŠã«æ倧1ã€ã®ãã£ãã«ã®æ å ±ãåŸ æ©ã§ãããšèšãããŠããŸããã
ããããgoã¯CPUæéãç¡é§ã«æ¶è²»ããããã§ã¯ãããŸããããã1ã€ã®åªããããŒã«ã¯selectã³ã³ã¹ãã©ã¯ãã§ãã
Selectã䜿çšãããšãç¡å¶éã®æ°ã®ãã£ãã«ããã®ããŒã¿ãæåŸ ã§ããåŠçäžã«æ¬¡ã®ããŒã¿ãå°çããå Žåã«ã®ã¿å®è¡ããããã¯ããŸãã å¿ èŠãªãã®ïŒ
ã³ãŒãã«åãæãããŸãããïŒ ãŸããå¿ èŠãªããã±ãŒãžãã€ã³ããŒãã»ã¯ã·ã§ã³ã«è¿œå ããŸããããã§ã次ã®ããã«ãªããŸãã
import ( "flag" "fmt" "github.com/opesun/goquery" "strings" "time" //, : "io" "os" "os/signal" // - : "crypto/md5" "encoding/hex" )
ã¯ãããããããããŸã... Goã®éçãªã³ã¯ãèãããšãå®è¡å¯èœãã¡ã€ã«ã®ãµã€ãºã¯ãã°ãããã¯ãã§ãïŒ
ããããããã¯æ²ããæã§ã¯ãããŸãããããã·ã¥çšã®ã¹ãã¬ãŒãžã宣èšããŸãïŒ
var ( ... used map[string]bool = make(map[string]bool) //map , - . )
ãããŠæåŸã«ãã¡ã€ã³é¢æ°ã¯æ¬¡ã®ããã«ãªããŸãã
func main() { // ... quotes_file, err := os.OpenFile(QUOTES_FILE, os.O_APPEND|os.O_CREATE, 0666) check(err) defer quotes_file.Close() //... hash_file, err := os.OpenFile(HASH_FILE, os.O_APPEND|os.O_CREATE, 0666) check(err) defer hash_file.Close() // Ticker ticker := time.NewTicker(time.Duration(REPORT_PERIOD) * time.Second) defer ticker.Stop() // , , ... key_chan := make(chan os.Signal, 1) signal.Notify(key_chan, os.Interrupt) //... hasher := md5.New() // quotes_count, dup_count := 0, 0 // , ! quotes_chan := grab() for { select { case quote := <-quotes_chan: // "" : quotes_count++ // , : hasher.Reset() io.WriteString(hasher, quote) hash := hasher.Sum(nil) hash_string := hex.EncodeToString(hash) // if !used[hash_string] { // - , used[hash_string] = true hash_file.Write(hash) quotes_file.WriteString(quote + "\n\n\n") dup_count = 0 } else { // - , ? if dup_count++; dup_count == DUP_TO_STOP { fmt.Println(" , . : ", len(used)) return } } case <-key_chan: // : fmt.Println("CTRL-C: . : ", len(used)) return case <-ticker.C: //, , fmt.Printf(" %d / %d (%d /) \n", len(used), dup_count, quotes_count/REPORT_PERIOD) quotes_count = 0 } } }
ã³ãŒãã¯å®å šã«ééçã§ããããã¡ã€ã«ãéãããšã®ã¿ã説æããŸãã
checkïŒïŒé¢æ°ã¯æšæºã§ã¯ãããŸãã-ããã¯ããã¡ã€ã«ãéããŠãšã©ãŒã®çµæã確èªããããã«äŸ¿å©ã§ãã ããã«ã³ãŒããããã mainïŒïŒã®åã®ã©ããã«çœ®ããŸãïŒ
func check(e error) { if e != nil { panic(e) } }
ãã1ã€ã®èå³æ·±ãç¹ã¯ããããã«ããã¡ã€ã«ãéããããã«ããããšã§ããããã®åŸã¯äœæ¥ãç¶ããŸãã
defer quotes_file.Close() ... defer hash_file.Close() ... // : defer ticker.Stop()
äžçªäžã®è¡ã¯ãé¢æ°ãdeferã§éå§ããããšã«ããããã®å®è¡ã延æããããšã§ããã€ãŸããé¢æ°ã¯deferåŒã³åºããå®äºããé¢æ°ã®åïŒã€ãŸããã芪ããæ»ãçŽåïŒã«ã®ã¿å®è¡ãããŸãã
ãã²ã©ãå¿ èŠãªããã·ã§ã³ãã®å®çŸããã§ã«éå§ããŠæ¥œããããšãã§ããŸããããã1ã€å°ããªè©³çŽ°ããããŸããããã°ã©ã ãå床å®è¡ãããããçµæã®ãã¡ã€ã«ã«éè€ãèŠãããªãããã«ããã¡ã€ã«ããããã·ã¥ãèªã¿åãé¢æ°ãèšè¿°ããå¿ èŠããããŸãã ãããè¡ã1ã€ã®æ¹æ³ã次ã«ç€ºããŸãã
func readHashes() { // if _, err := os.Stat(HASH_FILE); err != nil { if os.IsNotExist(err) { fmt.Println(" , .") return } } fmt.Println(" ...") hash_file, err := os.OpenFile(HASH_FILE, os.O_RDONLY, 0666) check(err) defer hash_file.Close() // 16 - : data := make([]byte, 16) for { n, err := hash_file.Read(data) //n , err - , . if err != nil { if err == io.EOF { break } panic(err) } if n == 16 { used[hex.EncodeToString(data)] = true } } fmt.Println(". : ", len(used)) }
ããã ãã§ããmainïŒïŒã®å é ã«readHashesïŒïŒåŒã³åºããé 眮ããããšãå¿ããªãã§ãã ãã
func main() { readHashes() ...
ã§ããïŒ æŠééå§ïŒ
ä»äºã®çµæïŒ
ãã¡ã€ã«ã®äœæãæ©èœããåèµ·åæã«ããã·ã¥ãåèªã¿èŸŒã¿ããŸãã 圌女ã¯åœä»€ã«ç«ã¡æ¢ãŸãã圌女èªèº«ãã§ããã ãã¡ãããå®è¡å¯èœãã¡ã€ã«ã¯å°ã倧ããã§ãããããã«åãããŠãã ããã
å€éã«éåžžã«éèŠãªããŒã¿ã®
ãã¡ãããæ°å€ãã®æ¹åç¹ããããŸããããã®ã³ãŒãã¯åçŽãªæŠéããã·ã§ã³ã«ã¯ååã§ãïŒ
Pastbin.comã®ããã°ã©ã ã³ãŒãå šäœ
Goãšãã®æ©èœã«èå³ãããå Žåã¯ã次ã®ãµã€ããã芧ãã ããã
tour.golang.org-èšèªã®ãªã³ã©ã€ã³ãã¢ãŒããã©ãŠã¶ã§ã³ãŒããçŽæ¥ç·šéããããšã¯éåžžã«ãšããµã€ãã£ã³ã°ã§ãã
gobyexample.com-å žåçãªã¿ã¹ã¯ã®äŸ
golang.org/ref/spec-èšèªä»æ§
golang.org/doc/effective_go.html- ããããŠä»ãç§ãã¡ã¯ãã®ãŽããã¹ãŠã§é¢éžããããšããŸãããšãããããã¯ã«é¢ããèšäº-æ£ããGoãé¢éžããŠé£ã¶æ¹æ³
Google Goã°ã«ãŒã-ã https://groups.google.com/forum/#!forum/golang-nuts ãããã³ã https://groups.google.com/forum/#!forum/golang-ru ã
godoc.org -Goããã±ãŒãžãšãã®ããã¥ã¡ã³ãïŒçµã¿èŸŒã¿ãšãµãŒãããŒãã£ã®äž¡æ¹ïŒãæ€çŽ¢ããããšã¯ãã¢ã³ããã€ã¯ã®çŽ æŽãããããšã§ãïŒ
é 匵ã£ãŠ