[go-nuts] Re: Help translate x86-64 assenbly to Go assembly
Managed to get this working The Go implementation now returns a monotonic time and works on 64 bit Intel Macs. Updated version at https://gist.github.com/namsral/376d0f063f631593a52e3f5b439e289c#file-time_amd64-v2-s On Tuesday, January 17, 2017 at 4:36:27 AM UTC+1, la...@namsral.com wrote: > > I want to add monotonic time to Go's runtime on macOS (x86-64) by > replacing Go's runtime,nanotime() to macOS' mach_absolute_time(). > > So far my Go assembly compiles but it returns the seconds since 1970-01-01 > instead of what mach_absolute_time() returns. > > What I have so far: > > https://gist.github.com/namsral/376d0f063f631593a52e3f5b439e289c#file-time_amd64-s > > mach_absolute_time in x86-64 assembly: > > https://gist.github.com/namsral/376d0f063f631593a52e3f5b439e289c#file-mach_absolute_time-s > > mach_absolute_time used in C: > > https://gist.github.com/namsral/376d0f063f631593a52e3f5b439e289c#file-time-c > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Test code that interacts with private variables and doesn't bloat binary
I' unsure if I understand the problem but code in *_test.go is not compiled into the production binary, so there is no need to extract test code into its own package: Keeping this in _test.go is probably okay. V. Am Dienstag, 17. Januar 2017 08:28:34 UTC+1 schrieb alcub...@gmail.com: > > I'm trying to test my packages without bloating the size of the binary. > Currently this consists of moving the test code into a test/ subdirectory. > If there's a better way to handle this, e.g. tree-shaking, please let me > know. > > Unfortunately, I have a package that needs to be initialized before use > (mainly connecting to a DB). For testing purposes, I have a mock > initialization routine. However, that initialization routine needs to > modify private variables, so I can't move it into test/. Is there any way > around this that avoids including the mock code in my production binary? > > Sincerely, > > Alex Becker > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Using GitHub projects with a local Go Environment
A package is just a folder. So you may have a repository having multiple packages for the same project, the project, among others, uses this layout, https://golang.org/pkg/ <> https://github.com/golang/go/tree/master/src. This said, for a go project hosted on github, you create a dir such as mkdir -p $GOPATH/src/github.com/USER/dummy You ll reference it with github.com/USER/dummy might this helps get you started https://github.com/mh-cbon/go-get-started On Tuesday, January 17, 2017 at 4:36:27 AM UTC+1, tahir.us...@gmail.com wrote: > > I recently set up a Go workspace environment on my Linux machine (running > Ubuntu 16.04), and I was able to setup GOPATH successfully, so that any > code I write in my src/ folder can be installed and sent to my bin/ folder, > and any custom packages I write in src/ (under a new sub-directory) can be > sent to a pkg/ folder. > > From here, is there a certain way I can package my code so that if I were > to make a project on GitHub, I can pull that project into my workspace, > create any custom packages I need for the project, and ship everything out > after I take care of dependencies? > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] exec.Command("cp", "-r", "./*.json", artifact.dir fails with exit status 1
On Mon, 16 Jan 2017 13:35:07 -0800 (PST) Deepak Jainwrote: > util.ExecuteCommandWithOuput(exec.Command("cp", "-r", "./*.json", > artifact. dir)) > > func ExecuteCommandWithOuput(cmd *exec.Cmd) { > output, err := cmd.Output() > if err != nil { > log.Print("Error executing ", cmd.Args, err) > } > fmt.Print(string(output)) > } > > Output > > 2017/01/16 13:26:35 Error executing [cp -r ./*.json myartifact] exit > status 1 > > Questions > 1. How do i get details of complete error message on failure of cp > command ? I did have err != nill and Print err The os/exec.Command() function constructs an value of type os/exec.Cmd which is a struct type describing the details of an external process to execute. Processes on Unix-like OSes (and Windows) have notions of the standard streams [2]. The "stderr" is where (well-written) programs write their error messages when they encounter a problem preventing them from completing their intended task. Values of the os/exec.Cmd have three fields, Stdin, Stdout and Stderr, which control the standard streams of the process to be executed, and as it happens by default these fields are initialized to nil which means the spawned process will have its standard streams connected to the so-called "null device" (/dev/null on Unices and NUL on Windows), and so its error output will go to nowhere. There are different approaches at handling error output of the external processes. 1. You can connect its Stderr to the Stderr of your running process which is available as os.Stderr, like this: cmd := exec.Command(`cp ...`) cmd.Stderr = os.Stderr and then whatever that `cp` process outputs will end up on the standard error stream of your host process. 2. You can "collect" that output and do something with it. One approach is to exploit the fact pointers to values of type bytes.Buffer implement the io.Writer interface, so you can do var errmsg bytes.Buffer cmd := exec.Command(`cp ...`) cmd.Stderr = err := cmd.Run() if err != nil || errmsg.Len() > 0 { log.Fatalf("Failed to copy: %s\n", errmsg.String()) } 3. The CombinedOutput() method of the os/exec.Cmd type provides a way to intelligently collect the outputs--to both the standard output stream and the standard error stream--of the process being executed and present them to you as a combined chunk of bytes. Such collection is done in an intelligent way -- by keeping only a manageable "header" and "trailer" parts of the output to deal with cases where a process spews enormous amounts of data, and you don't intend to process it all, and would be okay with just decorating those collected bits with some error message prefix and so on. > 2. Does exec.Command not support copy of files and recursive copy of > directories ? exec.Command() has nothing to do with copying anything. As its name suggests, it's a tool to execute external processes, and these processes can do anything. The `cp` program is for copying/linking filesystem entities but you could execute FireFox or Apache just as easily. > 3. Any suggestions how i implement copy of files and recursive copy > of directories ? [...] Answered over there at SO [1]. Here's my answer copied from there: >8 The problem To explain: the so-called "wildcards" are expanded by the shell in which you typically execute command-line commands. That is, when you invoke `cp -r ./*.json dir/`, the shell kicks in, expands *.json by itself—producing a list of names of the files matching that pattern and located in the current directory and pass the cp command a list of such names. So if you have, say, 10 matching files, the actuall call to cp will end up looking like cp -r file1.json file2.json ... dir/ When you pass call `cp ...` directly—without the shell kicking in and expanding that *.json "fileglob" for you, the cp command receives the name of a file "*.json" verbatim and attempts to open it. Since the file named exactly "*.json" supposedly does not exist, `cp` fails and exits. The solutions The first (admittedly lame) solution is to pass a call to cp "through" a shell. That is, turn your call to cp into a shell script and pass it to a shell. The simplest way to do this is to use something like exec.Command(`/bin/sh -c 'cp -r ./*.json manifest'`) This will call a shell `/bin/sh` and pass it the script to execute via its -c command-line option. Another solution is to roll copying yourself using the standard Go library: the functions of the path/filepath package provide support for both expanding fileglobs as the shell would do it and iterating over the entries of a given directory. Using either of these approaches you can build the list of files to copy and/or iterate over them. Then you can use the function os.OpenFile() to open the source and destination files, and io.Copy() to copy the contents between them.
[go-nuts] Test code that interacts with private variables and doesn't bloat binary
I'm trying to test my packages without bloating the size of the binary. Currently this consists of moving the test code into a test/ subdirectory. If there's a better way to handle this, e.g. tree-shaking, please let me know. Unfortunately, I have a package that needs to be initialized before use (mainly connecting to a DB). For testing purposes, I have a mock initialization routine. However, that initialization routine needs to modify private variables, so I can't move it into test/. Is there any way around this that avoids including the mock code in my production binary? Sincerely, Alex Becker -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: HTTP Server - Force close connection after response
You can use defer: defer bufrw.Flush() defer conn.Close() It will close after method finishs, but I do not know if it will work for you because you using go routines to start server, I never see this, I always use: log.Fatal(http.ListenAndServe(":8080", mux)) Well, I think you can try. Em segunda-feira, 16 de janeiro de 2017 23:36:27 UTC-4, Tony Grosinger escreveu: > > I would like to create an HTTP server which forces the connection to be > closed after writing the response. > For example: > > func closingHandler(w http.ResponseWriter, r *http.Request) { > // Respond before hijacking? > fmt.Fprintf(w, "Hello World") > > hj, ok := w.(http.Hijacker) > if !ok { > log.Println("Unable to create hijacker") > return > } > > conn, bufrw, err := hj.Hijack() > if err != nil { > log.Println("Unable to hijack request") > return > } > > bufrw.Flush() > conn.Close() > } > func main() { > mux := http.NewServeMux() > mux.HandleFunc("/", closingHandler) > > go func() { > err := http.ListenAndServe(":8080", mux) > if err != nil { > log.Println("Failed to run server" > } > }() > } > > This example does not work however because the client issuing the request > cannot successfully read the response. Is there another way to close the > connection manually that would allow me to respond to the HTTP request > first? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: exec.Command("cp", "-r", "./*.json", artifact.dir fails with exit status 1
The problem is expanding shell meta characters like *, ? and ~ is a property of the _shell_, as Dan mentioned above. You are executing a command directly so the shell is not involved and cannot expand *.json into a list of files ending with .json. A cheap solution to this might be something like util.ExecuteCommandWithOuput(exec.Command("sh", "-c", cp", "-r", *.json", artifact.dir)) Which will pass your command to sh to run, and thus expand (untested, but should be close). On Tuesday, 17 January 2017 18:02:17 UTC+11, Deepak Jain wrote: > > I appended pwd command output to source directory, i still get same error. > > pwd := util.ExecuteCommandWithOuput(exec.Command("pwd")) > fmt.Println("pwd", pwd) > util.ExecuteCommandWithOuput(exec.Command("cp", "-r", pwd+"/./*.json", > artifact.dir)) > > > Output: > > Cmd:[cp -r /Users/userId/sd101 /./*.json myartifact] > exit status 1: cp: /Users/userId/sd101 > /./*.json: No such file or directory > > I believed that above change should have worked. > > Any suggestions ? > > > > Appreciate your time. > > On Monday, January 16, 2017 at 7:35:57 PM UTC-8, Deepak Jain wrote: >> >> util.ExecuteCommandWithOuput(exec.Command("cp", "-r", "./*.json", >> artifact.dir)) >> >> func ExecuteCommandWithOuput(cmd *exec.Cmd) { >> output, err := cmd.Output() >> if err != nil { >> log.Print("Error executing ", cmd.Args, err) >> } >> fmt.Print(string(output)) >> } >> >> >> Output >> >> 2017/01/16 13:26:35 Error executing [cp -r ./*.json myartifact] exit >> status 1 >> >> >> Questions >> 1. How do i get details of complete error message on failure of cp >> command ? I did have err != nill and Print err >> 2. Does exec.Command not support copy of files and recursive copy of >> directories ? >> 3. Any suggestions how i implement copy of files and recursive copy of >> directories ? >> >> I have just started adopting Go and hence a new comer with Go. >> Regards, >> Deepak >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: exec.Command("cp", "-r", "./*.json", artifact.dir fails with exit status 1
I appended pwd command output to source directory, i still get same error. pwd := util.ExecuteCommandWithOuput(exec.Command("pwd")) fmt.Println("pwd", pwd) util.ExecuteCommandWithOuput(exec.Command("cp", "-r", pwd+"/./*.json", artifact.dir)) Output: Cmd:[cp -r /Users/userId/sd101 /./*.json myartifact] exit status 1: cp: /Users/userId/sd101 /./*.json: No such file or directory I believed that above change should have worked. Any suggestions ? Appreciate your time. On Monday, January 16, 2017 at 7:35:57 PM UTC-8, Deepak Jain wrote: > > util.ExecuteCommandWithOuput(exec.Command("cp", "-r", "./*.json", artifact > .dir)) > > func ExecuteCommandWithOuput(cmd *exec.Cmd) { > output, err := cmd.Output() > if err != nil { > log.Print("Error executing ", cmd.Args, err) > } > fmt.Print(string(output)) > } > > > Output > > 2017/01/16 13:26:35 Error executing [cp -r ./*.json myartifact] exit > status 1 > > > Questions > 1. How do i get details of complete error message on failure of cp command > ? I did have err != nill and Print err > 2. Does exec.Command not support copy of files and recursive copy of > directories ? > 3. Any suggestions how i implement copy of files and recursive copy of > directories ? > > I have just started adopting Go and hence a new comer with Go. > Regards, > Deepak > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Applying idiomatic Golang patterns to other languages?
Just curious how often you find yourself applying idiomatic Go patterns to other languages? (JavaScript, Python, C#, Java) For instance returning and handling an error value as opposed to throw-try-catch. I understand this isn't the best example since try-catch exceptions are more closely aligned to panics, but I do find myself returning more error values since using Go. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] RE: Using GitHub projects with a local Go Environment
I recently set up a Go workspace environment on my Linux machine (running Ubuntu 16.04), and I was able to setup GOPATH successfully, so that any code I write in my src/ folder can be installed and sent to my bin/ folder, and any custom packages I write in src/ (under a new sub-directory) can be sent to a pkg/ folder. >From here, is there a certain way I can package my code so that if I were to make a project on GitHub, I can pull that project into my workspace, create any custom packages I need for the project, and ship everything out after I take care of dependencies? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Remote address in SSH DialTCP must be IP address
That worked perfectly, thanks Dave. On Friday, January 13, 2017 at 12:09:35 PM UTC-8, Dave Cheney wrote: > > I'm pretty sure you can use the Dial method above, DialTCP was added to > avoid using the DNS server at the remote end (I think, it's been years) -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: My own Golang Playground?
Hi, Could you please elaborate? I don't seem to have the `tour` tool. How do you get it? Is it third party? On Tuesday, 24 May 2016 16:05:57 UTC+1, NagaSrinivasVinodKumar Panda wrote: > > "go tool tour" > That is it.. You have all you need with it, to have your exploration > offline.. > > On Wednesday, October 23, 2013 at 4:45:28 PM UTC+5:30, RickyS wrote: >> >> Is there an easy way for me to set up my own Golang playground on my own >> laptop, that I can use when disconnected from the Internet? >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] transport: http2Server.HandleStreams failed to read frame: read tcp 192.168.56.1:8080->192.168.56.1:29065: wsarecv: An existing connection was forcibly closed by the remote host.
Hi all, I am building a grpc server client communication on windows. I am getting error as transport: http2Server.HandleStreams failed to read frame: read tcp 192.168. 56.1:8080->192.168.56.1:29065: wsarecv: An existing connection was forcibly closed by the remote host. I am not able understand it. I googled about it but I no luck. I tried grpc sample code from https://github.com/grpc/grpc-go/tree/master/examples/helloworld/ on my system still getting similar error transport: http2Server.HandleStreams failed to read frame: read tcp [::1]: 50051->[::1]:28563: wsarecv: An existing connection was forcibly closed by the remote host. Server code: package main import ( "log" "net" "golang.org/x/net/context" "google.golang.org/grpc" pb "google.golang.org/grpc/examples/helloworld/helloworld" "google.golang.org/grpc/reflection" ) const ( port = ":50051" ) // server is used to implement helloworld.GreeterServer. type server struct{} // SayHello implements helloworld.GreeterServer func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb. HelloReply, error) { return {Message: "Hello " + in.Name}, nil } func main() { lis, err := net.Listen("tcp", port) if err != nil { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() pb.RegisterGreeterServer(s, {}) // Register reflection service on gRPC server. reflection.Register(s) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) } } Client code package main import ( "log" "os" "golang.org/x/net/context" "google.golang.org/grpc" pb "google.golang.org/grpc/examples/helloworld/helloworld" ) const ( address = "localhost:50051" defaultName = "world" ) func main() { // Set up a connection to the server. conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewGreeterClient(conn) // Contact the server and print out its response. name := defaultName if len(os.Args) > 1 { name = os.Args[1] } r, err := c.SayHello(context.Background(), {Name: name}) if err != nil { log.Fatalf("could not greet: %v", err) } log.Printf("Greeting: %s", r.Message) } I found something on googling as https://go.googlesource.com/net/+/master/http2/server.go https://golang.org/src/net/http/h2_bundle.go which tells problem is Windows OS specific. Not able to understand and find solution for it. if runtime.GOOS == "windows" { if oe, ok := err.(*net.OpError); ok && oe.Op == "read" { if se, ok := oe.Err.(*os.SyscallError); ok && se.Syscall == "wsarecv" { const WSAECONNABORTED = 10053 const WSAECONNRESET = 10054 if n := http2errno(se.Err); n == WSAECONNRESET || n == WSAECONNABORTED { return true } } } } Can anyone help me out in it ? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] exec.Command("cp", "-r", "./*.json", artifact.dir fails with exit status 1
util.ExecuteCommandWithOuput(exec.Command("cp", "-r", "./*.json", artifact. dir)) func ExecuteCommandWithOuput(cmd *exec.Cmd) { output, err := cmd.Output() if err != nil { log.Print("Error executing ", cmd.Args, err) } fmt.Print(string(output)) } Output 2017/01/16 13:26:35 Error executing [cp -r ./*.json myartifact] exit status 1 Questions 1. How do i get details of complete error message on failure of cp command ? I did have err != nill and Print err 2. Does exec.Command not support copy of files and recursive copy of directories ? 3. Any suggestions how i implement copy of files and recursive copy of directories ? I have just started adopting Go and hence a new comer with Go. Regards, Deepak -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: shiny: get mouse position relative to window
I haven't seen this either, the solution depends on what platform you're trying to support. I have a package that does this, for Win32. If you're using Windows, you use the the Rect() or ClientAbs() in my package to get the position of the window (or the client area). https://godoc.org/github.com/as/ms/win On Saturday, January 14, 2017 at 8:47:17 AM UTC-8, kty...@gmail.com wrote: > > How do I get the position for a mouse.Event in shiny using > golang.org/x/mobile/event.mouse? > > The position returned is the global position on the screen, which changes > if I move the window. > The comments in > https://github.com/golang/mobile/blob/master/event/mouse/mouse.go#L18 say > it's: > "// X and Y are the mouse location, in pixels.". It doesn't mention if > they are relative to the screen or the window. > > How do I get the position relative to the window? > Or is it an error of the driver (I'm using windows)? > Neither shiny.Screen nor shiny.Window have methods to get the current > position of the window. > > Example: > https://github.com/ktye/maps/blob/master/cmd/map/main.go#L101 > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.