code
stringlengths
10
1.34M
language
stringclasses
1 value
// A concurrent prime sieve package main // Send the sequence 2, 3, 4, ... to channel 'ch'. func Generate(ch chan<- int) { for i := 2; ; i++ { ch <- i // Send 'i' to channel 'ch'. } } // Copy the values from channel 'in' to channel 'out', // removing those divisible by 'prime'. func Filter(in <-chan int, out cha...
Go
package main import "fmt" func main() { fmt.Println("Hello, 世界") }
Go
// Concurrent computation of pi. // See http://goo.gl/ZuTZM. // // This demonstrates Go's ability to handle // large numbers of concurrent processes. // It is an unreasonable way to calculate pi. package main import ( "fmt" "math" ) func main() { fmt.Println(pi(5000)) } // pi launches n goroutines to compute an /...
Go
package main // fib returns a function that returns // successive Fibonacci numbers. func fib() func() int { a, b := 0, 1 return func() int { a, b = b, a+b return a } } func main() { f := fib() // Function calls are evaluated left-to-right. println(f(), f(), f(), f(), f()) }
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package rand2 /* #include <stdlib.h> */ import "C" func Random() int { var r C.long = C.random() return int(r) } // STOP OMIT func Seed(i int) { C.srandom(...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "math" ) func InterfaceExample() { var i interface{} i = "a string" i = 2011 i = 2.777 // STOP OMIT r := i.(float64) fm...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "The Laws of Reflection." package main import ( "fmt" "reflect" ) func main() { var x float64 = 3.4 f...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "image" ) func main() { r := image.Rect(2, 1, 5, 5).Add(image.Pt(-4, -2)) fmt.Println(r.Dx(), r.Dy(), image.Pt(0, 0).In(r)) //...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "The Laws of Reflection." package main import ( "bufio" "bytes" "io" "os" ) type MyInt int var i int...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package print // #include <stdio.h> // #include <stdlib.h> import "C" import "unsafe" func Print(s string) { cs := C.CString(s) C.fputs(cs, (*C.FILE)(C.stdou...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package timeout import ( "time" ) func Timeout() { ch := make(chan bool, 1) timeout := make(chan bool, 1) go func() { time.Sleep(1 * time.Second) timeo...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) func init() { http.HandleF...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) func init() { http.Handle(...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "encoding/json" "fmt" "log" "reflect" ) func Decode() { b := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`) ...
Go
package main import ( "flag" "log" "net/http" "text/template" ) var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18 var templ = template.Must(template.New("qr").Parse(templateStr)) func main() { flag.Parse() http.Handle("/", http.HandlerFunc(QR)) err := http.ListenAndServe(*addr, ni...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "Error Handling and Go." package main import ( "encoding/json" "errors" "fmt" "log" "net" "os" "tim...
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "fmt" type ByteSize float64 const ( _ = iota // ignore first value by assigning to blank identifier KB ByteSize = 1 << (10 * ...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package gobs1 type T struct{ X, Y, Z int } // Only exported fields are encoded and decoded. var t = T{X: 7, Y: 0, Z: 8} // STOP OMIT type U struct{ X, Y *int...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package rand /* #include <stdlib.h> */ import "C" // STOP OMIT func Random() int { return int(C.random()) } // STOP OMIT func Seed(i int) { C.srandom(C.uint...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "image" ) func main() { r := image.Rect(0, 0, 4, 3).Intersect(image.Rect(2, 2, 5, 5)) // Size returns a rectangle's width and ...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "image" ) func main() { r := image.Rect(2, 1, 5, 5) // Dx and Dy return a rectangle's width and height. fmt.Println(r.Dx(), r...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "encoding/json" "log" "os" ) func main() { dec := json.NewDecoder(os.Stdin) enc := json.NewEncoder(os.Stdout) for { var v map[st...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "image" "image/color" ) func main() { m := image.NewRGBA(image.Rect(0, 0, 640, 480)) m.Set(5, 5, color.RGBA{255, 0, 0, 255}) ...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains examples to embed in the Go 1 release notes document. package main import ( "errors" "flag" "fmt" "log" "os" "path/filepath" "tes...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "Defer, Panic, and Recover." package main import "fmt" import "io" // OMIT import "os" // OMIT func main(...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "io/ioutil" "regexp" ) func AppendByte(slice []byte, data ...byte) []byte { m := len(slice) n := m + len(data) if n > cap(slice) { ...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "Defer, Panic, and Recover." package main import ( "fmt" "io" "os" ) func a() { i := 0 defer fmt.Pri...
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "sort" ) func main() { seq := Sequence{6, 2, -1, 44, 16} sort.Sort(seq) fmt.Println(seq) } type Sequence []int // Methods r...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "The Go image/draw package." package main import ( "image" "image/color" "image/draw" ) func main() { ...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "image" ) func main() { p := image.Point{2, 1} fmt.Println("X is", p.X, "Y is", p.Y) }
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "encoding/json" "log" "reflect" ) type FamilyMember struct { Name string Age int Parents []string } // STOP OMIT func Dec...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // This file contains the code snippets included in "Error Handling and Go." package main import ( "net/http" "text/template" ) type appError struct { Err...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "bytes" "encoding/gob" "fmt" "log" ) type P struct { X, Y, Z int Name string } type Q struct { X, Y *int32 Name string } fu...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "image" ) func main() { m0 := image.NewRGBA(image.Rect(0, 0, 8, 5)) m1 := m0.SubImage(image.Rect(1, 2, 5, 5)).(*image.RGBA) f...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package query type Conn string func (c Conn) DoQuery(query string) Result { return Result("result") } type Result string func Query(conns []Conn, query stri...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package print // #include <stdio.h> // #include <stdlib.h> import "C" import "unsafe" func Print(s string) { cs := C.CString(s) defer C.free(unsafe.Pointer(c...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "encoding/json" "log" "reflect" ) type Message struct { Name string Body string Time int64 } // STOP OMIT func Encode() { m := ...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. /* Generating random text: a Markov chain algorithm Based on the program presented in the "Design and Implementation" chapter of The Practice of Programming (...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "math/rand" ) const ( win = 100 // The winning score in a game of Pig gamesPerSeries = 10 // The number of games p...
Go
// Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "log" "net/http" "time" ) const ( numPollers = 2 // number of Poller goroutines to launch pollInterval = 60 * ...
Go
package main import "fmt" import "os" import "path/filepath" import "time" import "strings" import "io/ioutil" var smap map[string]int64 func walkFunc(path string, info os.FileInfo, err error) error { var errorRet error var arPath []string = strings.Split(path, "\\") //if err == nil { // retu...
Go
// Copyright 2012 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable...
Go
// Copyright 2012 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable...
Go
// Copyright 2012 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable...
Go
// Copyright 2012 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable...
Go
// Copyright 2012 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable...
Go
// By: Tom Wambold <tom5760@gmail.com> package main import "other" func main() { a := other.Vector3 {1, 2, 3}; a.Size(); return; }
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "cgo/stdio" func main() { stdio.Stdout.WriteString(stdio.Greeting + "\n") }
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. /* A trivial example of wrapping a C library in Go. For a more complex example and explanation, see ../gmp/gmp.go. */ package stdio /* #include <stdio.h> #in...
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Compute Fibonacci numbers with two goroutines // that pass integers back and forth. No actual // concurrency, just threads and synchronization // and forei...
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Pass numbers along a chain of threads. package main import ( "runtime" "cgo/stdio" "strconv" ) const N = 10 const R = 5 func link(left chan<- int, ri...
Go
package main import "foo" func main() { foo.MyHello("hello from my-c-lib\n") foo.MyBye("bye from my-c-lib\n") } // EOF
Go
/* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form ...
Go
package foo /* #cgo LDFLAGS: -lmy-c-lib #include "my-c-lib.h" #include <stdlib.h> */ import "C" import "unsafe" func MyBye(msg string) { c_msg := C.CString(msg) defer C.free(unsafe.Pointer(c_msg)) C.my_c_bye(c_msg) }
Go
// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package gmp // #include <gmp.h> // #include <stdlib.h> // #cgo LDFLAGS: -lgmp import "C" import ( "os" "unsafe" ) /* * one of a kind */ // An Int repre...
Go
package other type Foo interface { Get(i int, j int) float64; Set(i int, j int, v float64); }
Go
// By: Tom Wambold <tom5760@gmail.com> package other import "math" // A three-value vector (i, j, k) type Vector3 [3]float64 func (a *Vector3) Size() float64 { return math.Sqrt(float64(a[0] * a[0] + a[1] * a[1] + a[2] * a[2])); }
Go
package foo /* #cgo LDFLAGS: -lmy-c-lib #include "my-c-lib.h" #include <stdlib.h> */ import "C" import "unsafe" func MyHello(msg string) { c_msg := C.CString(msg) defer C.free(unsafe.Pointer(c_msg)) C.my_c_hello(c_msg) }
Go
package gmp /* #include <stdio.h> */ import "C" // EOF
Go
package main import( "http" "fmt" "runtime" ) var RequestCount int=0 var OnRequestChan chan int func main(){ Log("Read Config...") ReadConfig("") Log("Start Server...") OnRequestChan=make(chan int) http.HandleFunc("/",RootHandler) http.HandleFunc("/get_property",GetPropertyHandler) http.HandleFunc("/file",Get...
Go
package main import( "fmt" "os" "syscall" ) var ( Stdin = os.NewFile(syscall.Stdin, "/dev/stdin") Stdout = os.NewFile(syscall.Stdout, "/dev/stdout") Stderr = os.NewFile(syscall.Stderr, "/dev/stderr") ) func Log(s string){ fmt.Fprintln(Stdout,s) } func LogError(err os.Error) bool{ if(err!=nil){ fmt.Fpri...
Go
package system import( "container/list" "runtime" "os" "fmt" "bytes" "mime" "os/user" ) const ( //获取系统属性需要的名称 PROPERTY_PATH_SEPARATOR="PathSeparator" PROPERTY_USER="User" PROPERTY_HOST_NAME="HostName" PROPERTY_OS="OS" PROPERTY_LIST_MAX=128 ) var OSName=runtime.GOOS type ( //系统的实例 SystemInstance interface...
Go
package system import( "os" "path/filepath" "os/user" "fmt" ) type OS struct{ } //获取主机名 func (this *OS) GetHostName() string{ name,_:=os.Hostname() return name } //获取指定文件的信息,如果是目录的话,读取子文件信息 func (this *OS) GetFileInfo(v string) *SystemFile{ if v==""{return nil} if !filepath.IsAbs(v){ fmt.Println(v) file:=S...
Go
package system import( "os" ) type Linux struct{ OS } //获取主机home路径 func (this *Linux) GetHomeFolder() string{ return os.Getenv("HOME") } func (this *Linux) Open(path string) (*os.File,os.Error){ return os.Open(path) } func (this *Linux) GetDriveList() string{ return "" }
Go
package system import( "os" "path/filepath" "os/user" ) type Windows struct{ OS } func (this *Windows) GetHomeFolder() string{ return "" } func (this *Windows) Open(path string) (*os.File,os.Error){ path,_=filepath.Abs(path) path=filepath.FromSlash(path) return os.Open(path) } func (this *Windows) GetUser() (*u...
Go
package main import( "http" "io/ioutil" "json" "system" "fmt" "container/list" "bytes" "path/filepath" "os" "image" "image/png" "encoding/base64" ) /* 处理url请求 */ func ThumbnailsHandler(response http.ResponseWriter,r *http.Request){ err:=r.ParseForm() if LogError(err){ response.WriteHeader(http.StatusBad...
Go
// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "image" "image/ycbcr" ) // Resize returns a scaled copy of the image slice r of m. // The returned image has width w and height h. fun...
Go
package main import( "os" "io/ioutil" "json" "image" "image/jpeg" "image/bmp" "image/gif" "image/png" "image/tiff" ) type ConfigT struct{ Port int Resource map[string]string HTML,Index string } var Config *ConfigT const DEFAULT_CONFIG_FILE string="server_config.json" /* 读取配置文件内容,默认配置文...
Go
// +build !windows package main import ( "crypto/sha1" "flag" "fmt" "io" "log" "os" "os/exec" "path/filepath" "time" ) func init() { altMain = notWindowsMain } var buildWindows = flag.Bool("newwin", false, "force a make.bash of windows_386") func notWindowsMain() { build := flag.Bool("build", false, "bu...
Go
// +build !windows package main import ( "bufio" "bytes" "encoding/base64" "errors" "fmt" "io" "mime/multipart" "net/http" "os" "path/filepath" "strings" ) const ( uploadURL = "https://winstrap.googlecode.com/files" ) func parseNetRC() (user, pass string, err error) { f, err := os.Open(filepath.Join(os...
Go
package main import ( "bufio" "flag" "fmt" "io" "log" "net/http" "os" "os/exec" "path/filepath" "runtime" "strings" "sync" ) var files = map[string]string{ "ChromeStandaloneSetup.exe": "https://dl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7BC159FD9F-6827-8E7E-0CC8-778...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // Package svc provides everything required to build Windows service. // package svc import ( "code.google.com/p/winsvc/winapi" "errors" ...
Go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // +build go1.3 package svc import "unsafe" const ptrSize = 4 << (^uintptr(0) >> 63) // unsafe.Sizeof(uintptr(0)) but an ideal const // S...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package svc import ( "code.google.com/p/winsvc/winapi" "syscall" "unsafe" ) // TODO(brainman): move some of that code to syscall/securit...
Go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // +build !go1.3 package svc // from go12.c func getServiceMain(r *uintptr)
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package svc import ( "code.google.com/p/winsvc/winapi" "errors" "syscall" ) // event represents auto-reset, initially non-signaled windo...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package winapi const ( SC_MANAGER_CONNECT = 1 << iota SC_MANAGER_CREATE_SERVICE SC_MANAGER_ENUMERATE_SERVICE SC_MANAGER_LOCK SC_MANAGER...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package winapi const ( REG_OPTION_NON_VOLATILE = 0 REG_CREATED_NEW_KEY = 1 REG_OPENED_EXISTING_KEY = 2 ) //sys RegCreateKeyEx(key s...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package winapi const ( EVENTLOG_ERROR_TYPE = 1 << iota EVENTLOG_WARNING_TYPE EVENTLOG_INFORMATION_TYPE EVENTLOG_AUDIT_SUCCESS EVENTLOG_...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package winapi import "syscall" const ( STANDARD_RIGHTS_REQUIRED = 0xf0000 ERROR_SERVICE_SPECIFIC_ERROR syscall.Errno = 1066 ) //sys Ge...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package winapi import "syscall" type SidIdentifierAuthority struct { Value [6]byte } var ( SECURITY_NULL_SID_AUTHORITY = SidIdent...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package winapi //sys CreateEvent(eventAttrs *syscall.SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle sysc...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // Package registry provides access to Windows registry. // package registry import ( "code.google.com/p/winsvc/winapi" "syscall" "unsafe...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // Example service program that beeps. It demonstrates how to // create a service and install / remove it on a computer. // It also shows how...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package main import ( "syscall" ) // BUG(brainman): MessageBeep Windows api is broken on Windows 7, // so this example does not beep when ...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package main import ( "code.google.com/p/winsvc/debug" "code.google.com/p/winsvc/eventlog" "code.google.com/p/winsvc/svc" "fmt" "time" ...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package main import ( "code.google.com/p/winsvc/eventlog" "code.google.com/p/winsvc/mgr" "fmt" "os" "path/filepath" ) func exePath() (...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package main import ( "code.google.com/p/winsvc/mgr" "code.google.com/p/winsvc/svc" "fmt" "time" ) func startService(name string) error...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package mgr import ( "code.google.com/p/winsvc/svc" "code.google.com/p/winsvc/winapi" "syscall" ) // TODO(brainman): use EnumDependentSe...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // Package mgr can be used to manage Windows service programs. // It can be used to install and remove them. It can also start, // stop, paus...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package mgr import ( "code.google.com/p/winsvc/winapi" "syscall" "unicode/utf16" "unsafe" ) const ( // Service start types StartManua...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows // Package eventlog implements access to Windows event log. // package eventlog import ( "code.google.com/p/winsvc/winapi" "errors" "sysc...
Go
// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // +build windows package eventlog import ( "code.google.com/p/winsvc/registry" "code.google.com/p/winsvc/winapi" "errors" "syscall" ) const ( // Log le...
Go
// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved. package log4go import ( "io" "os" "fmt" ) var stdout io.Writer = os.Stdout // This is the standard writer that prints to standard output. type ConsoleLogWriter chan *LogRecord // This creates a new ConsoleLogWriter func NewConsoleLo...
Go
// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved. package log4go import ( "fmt" "bytes" "io" ) const ( FORMAT_DEFAULT = "[%D %T] [%L] (%S) %M" FORMAT_SHORT = "[%t %d] [%L] %M" FORMAT_ABBREV = "[%L] %M" ) type formatCacheType struct { LastUpdateSeconds int64 shortTime, sho...
Go
// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved. package log4go import ( "errors" "os" "fmt" "strings" ) var ( Global Logger ) func init() { Global = NewDefaultLogger(DEBUG) } // Wrapper for (*Logger).LoadConfiguration func LoadConfiguration(filename string) { Global.LoadConfi...
Go
// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved. package log4go import ( "os" "fmt" "time" ) // This log writer sends output to a file type FileLogWriter struct { rec chan *LogRecord rot chan bool // The opened file filename string file *os.File // The logging format fo...
Go
// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved. package log4go import ( "encoding/xml" "fmt" "io/ioutil" "os" "strconv" "strings" ) type xmlProperty struct { Name string `xml:"name,attr"` Value string `xml:",chardata"` } type xmlFilter struct { Enabled string `xml:"...
Go
// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved. // Package log4go provides level-based and highly configurable logging. // // Enhanced Logging // // This is inspired by the logging functionality in Java. Essentially, you create a Logger // object and create output filters for it. You ...
Go
package main import ( "flag" "fmt" "net" "os" ) var ( port = flag.String("p", "12124", "Port number to listen on") ) func e(err error) { if err != nil { fmt.Printf("Erroring out: %s\n", err) os.Exit(1) } } func main() { flag.Parse() // Bind to the port bind, err := net.ResolveUDPAddr("0.0.0.0:" + *po...
Go