webuser1200 | 19 Apr 17:46 2015
Picon

Confused with sqlx db.Select

From the documentation:


// Query the database, storing results in a []Person (wrapped in []interface{})
    people := []Person{}
    db.Select(&people, "SELECT * FROM person ORDER BY first_name ASC")
    jason, john := people[0], people[1]

I have to pass people to another function and it's a large struct so would like to pass the pointer:


for _, p := range people {
   some_func(&p)
   fmt.Printf("%p=%p", &p)


When I do the above the pointer for each &p is the same. I guess I'm getting the address of the interface....I'm confused...

Should I not be getting a different pointer on each iteration of the loop and if so, how do I pass the actual &p to my function....

Thanks

WU

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Drew Wells | 19 Apr 16:27 2015
Picon

Compiling C++ software

With swig integration, it's not very easy to link to C++ code by the auto generated code from SWIG. Is it also possible via the Go build chain to provide compile and then link to C++ libraries?

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Art Mellor | 19 Apr 15:35 2015
Picon

Do I need to worry about this race condition?

I have a race condition that is clearly real. I don't think it will cause a problem, but I wanted to make sure I'm not missing something non-obvious, either in a side-effect or in a better way to do it.

Below is a stripped down toy version of what I'm working with, I also have it in the playground. The race condition output is below the code listing.

Basically, I'm swapping out a func in a var to turn debug output on/off. My thoughts are that the assignment is "atomic" and thus I'm not at risk for unexpected behavior. I realize I could embed it in a struct with appropriate methods and a lock, but I like having it behave as a straight func.

(obviously running it in the playground won't show the -race output)

It's a go routine printing debug output and a main routine turning the debug on and off.

Is there something bad possibly happening that I'm missing or a better way to do this. I also like having clean -race output.
Thanks!

package main
import (
    "fmt"
    "time"
)
func DebugOn(fmtstr string, args ...interface{}) {
    fmt.Printf(fmtstr, args...)
    return
}
func DebugOff(fmtstr string, args ...interface{}) {
    return
}
var Debug = DebugOn
func main() {
    go func() {
        for i := 1; i <= 100; i++ {
            Debug("%03d: Debug\n", i)
            time.Sleep(100 * time.Millisecond)
        }
    }()
    for i := 1; i <= 5; i++ {
        time.Sleep(1 * time.Second)
        Debug = DebugOff
        time.Sleep(1 * time.Second)
 Debug = DebugOn
    }
    return
}
/*
==================
WARNING: DATA RACE
Write by main goroutine:
  main.main()
      /emu/build/art/repo/Go/src/race/race.go:30 +0x6c
Previous read by goroutine 5:
  main.func-001()
      /emu/build/art/repo/Go/src/race/race.go:23 +0xf1
Goroutine 5 (running) created at:
  main.main()
      /emu/build/art/repo/Go/src/race/race.go:26 +0x37
==================
*/

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
leonbogaert | 18 Apr 23:21 2015
Picon

syscall / unsafe.Pointer() only works when using fmt.Println()

I have a small issue with a syscall that fails sometimes.

This doesn't work (I get 'Path not found' from the syscall):

hMemMapFile, _, err := wOpenFileMappingW.Call(
uintptr(dwDesiredAccess), // DWORD
0, // BOOL
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpName))), // LPCTSTR
)

 This does work:

// Without Println() wOpenFileMappingW.Call) fails
fmt.Println("")
 
hMemMapFile, _, err := wOpenFileMappingW.Call(
uintptr(dwDesiredAccess), // DWORD
0, // BOOL
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpName))), // LPCTSTR
)

This also works:

test1 := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpName)))
hMemMapFile, _, err := wOpenFileMappingW.Call(
uintptr(dwDesiredAccess), // DWORD
0, // BOOL
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpName))), // LPCTSTR
)
fmt.Println(test1) 

This doesn't work (Path not found):

hMemMapFile, _, err := wOpenFileMappingW.Call(
uintptr(dwDesiredAccess), // DWORD
0, // BOOL
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpName))), // LPCTSTR
)
test1 := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpName)))
fmt.Println(test1)

I'm running the go program under wine. So maybe that's related. I'm wondering what could cause this kind of behavior.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Thiago Farina | 18 Apr 04:39 2015

GOPATH requeriment

Hi goers,

I just wanted to ask if one day the requirement of GOPATH will ever be dropped?

I mean, I see this as serious limitation and a lack of freedom when working with Go code.

Why should I be constrained to a single location of where to put my go code?

It would be much more fetterless if I could check out a project from Github anywhere I want, just build it and install (like it is with C and Autotools projects), rather than be forced to put everything under GOPATH.

Best regards,



--
Thiago Farina

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tong Sun | 18 Apr 22:07 2015
Picon

Use Semantic UI (Node.js) with Go

Hi, 

I'm planning to use Go to construct my back-end server. I've found a really good/excellent get-started project, https://github.com/pkieltyka/godo-app, by Peter Kieltyka (and the presentation is here BTW https://speakerdeck.com/pkieltyka/building-a-rest-api-service-in-go). 

Also, I want to use Semantic UI (http://semantic-ui.com/) to ease my front-end development, but the problem is that it depends on Node.js. So my question is, 

Is it possible for the Goji web framework (that the demo project uses) to route some requests to the Node.js server on the same machine? 

More info if it helps -- I'm a backend C/C++ programmer so all these are new to me. I'm planning to use the plain GO http server at first, then gradually adding interactions. If the above is too difficult or impossible, what kind of easy to use front-end platform I can use to go nicely with GO? The thing I like about Semantic-UI is its declarative-GUI feature. What ever the GUI component it is, you just declare it, be it menu, progress bar, etc. The platform takes care of the details. 


Thanks

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Tester | 18 Apr 18:17 2015
Picon

smtp send email

Hello Gophers,

I have a problem
When I try to send email by smtp package 
The sender message is my smtp user, not user who send a message
Is there a way to make the sender from user not smtp user?

my example

func SendEmail(name, email, to, subject, msg,
 smtpUser
, smtpPass, smtpProvider, smtpPort string) {


 
var rawMsg = "From: %s <%s>"
 rawMsg
+= "\nTo: %s"
 rawMsg
+= "\nSubject: %s"
 rawMsg
+= "\nMIME-Version: 1.0"
 rawMsg
+= "\nContent-Type: text/html; charset=utf-8"
 rawMsg
+= "\nContent-Transfer-Encoding: plain"
 rawMsg
+= "\n\n%s"


 
// Set up authentication information.
 auth
:= smtp.PlainAuth("",
 smtpUser
,
 smtpPass
,
 smtpProvider
,
 
)


 
// Connect to the server, authenticate, set the sender and recipient,
 
// and send the email all in one step.
 body
:= fmt.Sprintf(rawMsg, name, email, to, subject, msg)


 err
:= smtp.SendMail(smtpProvider+":"+smtpPort,
 auth
,
 email
,
 
[]string{to},
 
[]byte(body),
 
)
 
if err != nil {
 
Logs(err)
 
}
}

name := "My Name"
email
:= "me-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org"
to
:= "m <at> golang.com"
subject
:= "My subject"
smtpUser
:= "?????? <at> gmail.com"
smtpPass
:= "**********"
smtpProvider
:= "smtp.gmail.com"
smtpPort
:= "587"


SendEmail(name, email, to, subject, msg, smtpUser, smtpPass, smtpProvider, smtpPort)

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Mohamedh Fazal | 18 Apr 12:10 2015
Picon

Handling logging, auditing and bench-marking through an event system

Hello Gophers,

I've got a bit of a doubt in terms on handling logging, auditing and benchmarking (How fast an HTTP Handler responded and such) with idiomatic go. What I want to do is handle all of these centrally in the application so that Handlers themselves are pretty clean.


I created the above to explain what I'm trying to achieve. 

My questions are:

1. Is this pattern idiomatic?
2. How can I use Go's concurrency facilities here. (Emit in a goroutine?, Send events through a channel and emit to sinks within a select?) 

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
bx10000 | 18 Apr 02:58 2015
Picon

Convert int to int32 or int64

Is there a way to convert an int to int64?

I know you can convert int to int64 by doing int64(int).

Thanks in advance.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
webuser1200 | 17 Apr 20:09 2015
Picon

Problem getting gopacket

I'm on ubuntu 14.04

I ran:

go get code.google.com/p/gopacket/pfring

But am getting the following error:

# code.google.com/p/gopacket/pfring
src/code.google.com/p/gopacket/pfring/pfring.go:13:20: fatal error: pfring.h: No such file or directory
 #include <pfring.h>

I installed pcap-dev:

sudo apt-get install libpcap-dev

Any ideas what I'm doing wrong?

Regards,

WU

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.
Alex Browne | 17 Apr 19:48 2015
Picon

Background Jobs Library for Go (like Sidekiq/Resque/DelayedJob)

I built a background jobs library powered by redis to solve the kinds of problems I face all the time when building web apps with go. I took great care in building the library to provide certain guarantees and it's really well tested. If you plan on using this I'd love to hear what you're building. If you have any feedback or ideas for new features I'd love to hear that too!

Jobs supports the following features:

  • A job can encapsulate any arbitrary functionality. A job can do anything which can be done in a go function.
  • A job can be one-off (only executed once) or recurring (scheduled to execute at a specific interval).
  • A job can be retried a specified number of times if it fails.
  • A job is persistent, with protections against power loss and other worst case scenarios. (See the Guarantees section in the README)
  • Work on jobs can be spread amongst any number of concurrent workers across any number of machines.
  • Provided it is persisted to disk, every job will be executed at least once, and in ideal network conditions will be executed exactly once. (See the Guarantees section in the README)
  • You can query the database to find out e.g. the number of jobs that are currently executing or how long a particular job took to execute.
  • Any job that permanently fails will have its error captured and stored.
If you are not familiar with Sidekiq/Resque/DelayedJob, here's an excerpt from the README about how the library can be used:

Jobs is intended to be used in web applications. It is useful for cases where you need to execute some long-running code, but you don't want your users to wait for the code to execute before rendering a response. A good example is sending a welcome email to your users after they sign up. You can use Jobs to schedule the email to be sent asynchronously, and render a response to your user without waiting for the email to be sent. You could use a goroutine to accomplish the same thing, but in the event of a server restart or power loss, the email might never be sent. Jobs guarantees that the email will be sent at some time, and allows you to spread the work between different machines.

Cheers!

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Gmane