Jacob Arthur | 19 Dec 22:45 2014
Picon

multiChan design

I don't really know how to describe this so it was hard to search if anyone else has come up with something similar and/or better for what I'm trying to do.

http://play.golang.org/p/izPUTlxU3J

Basically I wanted to create a wrapper around a channel that can handle the opening and closing the comm from multiple go routines and fan it into a standard channel. I can't be the only person who has needed this so I really wanted to see how other people solved the problem, and if not at least share the way I thought about it.

Thanks,
Jacob





--
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.
Tad Vizbaras | 19 Dec 18:16 2014
Picon

Trying to return func from func

type IteratorFunc func() bool

func Iterator(count int) IteratorFunc {
c := count
return IteratorFunc {
c--
return c > 0
}
}

Simple enough but fails on line "c--". Error from go build is:

./testcmd.go:12: syntax error: unexpected --, expecting }
./testcmd.go:15: syntax error: unexpected }

It does work if I do this:

type IteratorFunc func() bool

func Iterator(count int) IteratorFunc {
c := count
return func() bool {
c--
return c > 0
}
}

Why does #1 do not work? I know I am missing something very obvious.

--
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 Saskevich | 19 Dec 18:07 2014
Picon

[ANN] EventBus - little and lightweight eventbus for GoLang.

EventBus (https://github.com/asaskevich/EventBus)

Package EventBus is the little and lightweight eventbus for GoLang.

Installation

Make sure that Go is installed on your computer. Type the following command in your terminal:

go get github.com/asaskevich/EventBus

After it the package is ready to use.

Import package in your project

Add following line in your *.go file:

import "github.com/asaskevich/EventBus"

If you unhappy to use long EventBus, you can do something like this:

import ( evbus "github.com/asaskevich/EventBus" )

Example

func calculator(a int, b int) { fmt.Printf("%d\n", a + b) } func main() { bus := EventBus.New(); bus.Subscribe("main:calculator", calculator); bus.Publish("main:calculator", 20, 40); bus.Unsubscribe("main:calculator"); }

Implemented methods

  • New()
  • Subscribe()
  • SubscribeOnce()
  • Unsubscribe()
  • Publish()

New()

New returns new EventBus with empty handlers.

bus := EventBus.New();

Subscribe(channel string, fn interface{})

Subscribe to a channel.

func Handler() { ... } ... bus.Subscribe("channel:handler", Handler)

SubscribeOnce(channel string, fn interface{})

Subscribe to a channel once. Handler will be removed after executing.

func HelloWorld() { ... } ... bus.SubscribeOnce("channel:handler", HelloWorld)

Unsubscribe(channel string)

Remove callback defined for a channel.

bus.Unsubscribe("channel:handler");

Publish(channel string, args ...interface{})

Execute callback defined for a channel. Any addional argument will be tranfered to the callback.

func Handler(str string) { ... } ... bus.Subscribe("channel:handler", Handler) ... bus.Publish("channel:handler", "Hello, World!");

Support

If you do have a contribution for the package feel free to put up a Pull Request or open Issue.

--
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.
Cory Gideon | 19 Dec 17:46 2014
Picon

Go Mobile Web Application

Hello,

I'm fairly new with Go and was wondering if anyone has experience writing mobile web applications in Go? I have a project I want to work on where it will work with a document database, most likely Mongo, to store information but also have a chat function for the users as well as the ability to create and add custom buttons to each individual's UI. I'm not sure if this can be done in Go but I wanted to see if anyone has experience and would be willing to share any lessons learned in writing a mobile web app in Go.

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.
Chris Hinsley | 19 Dec 17:03 2014
Picon

go chess

My first Go program.

Best Regards

Chris

--
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.
Attachment (chess.go): application/octet-stream, 15 KiB
Luke Mauldin | 19 Dec 16:46 2014
Picon

Reverse displaying file

All,

I know this has to be simple but I am currently stumped.  I am reading in a file that has lines delimited by "\n" and I want to reverse the order of the lines and then display it to the user.  The scenario is actually a log file viewer.  I have extracted the part of the code that is giving me the problem to: https://play.golang.org/p/dyIydUamOI

Currently this code gives me the error: panic: interface conversion: sort.Interface is *sort.reverse, not sort.StringSlice

After I call 'sort.Reverse', I do not know how to get access to the underlying []string slice that has been reversed?


--
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.
Mathieu Lonjaret | 19 Dec 16:00 2014
Picon

html/template: is this working as intended?

Hi,

http://play.golang.org/p/DCAjDigy3y

I kindof get what is happening, i.e. that the code within the if block
is parsed regardless of whether the condition is true, so that the
package can keep its safety promise, I suppose? Which is also probably
why ExecuteTemplate does not error if this code is used with
text/template instead?
Nonetheless, I just wanted to make sure this is what was intended with
the behaviour of the {{if pipeline}} action, since I didn't expect
this error to happen just from reading the doc. Or maybe I missed the
bit about it.

Thoughts?

Thanks,
Mathieu

--

-- 
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@...
For more options, visit https://groups.google.com/d/optout.

pangzi.sjtu | 19 Dec 10:23 2014
Picon

gccgo compile issue: __morestack_non_split

I want to call go from ruby. 
I followed the answer but failed in the last step
http://stackoverflow.com/questions/15879993/writing-a-ruby-extension-in-go-golang

gccgo -shared -Wl,-soname,libgofuncs.so -o libgofuncs.so goFuncs.o glue.o
/usr/bin/ld.gold: error: goFuncs.o: could not convert call to '__morestack' to '__morestack_non_split' 
collect2: error: ld returned 1 exit status 

Is it a gccgo issue?

ENV:
Ubuntu 14.04
gccgo 4.9 (installed by apt-get)

--
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.
Jia Mi | 19 Dec 14:03 2014
Picon

Cache implementation: channel mux vs. RWMutex

Hi,

I am trying to implement a cache which can have expiration for keys. As I know there are some implementations and most of them are using RWMutex to protect the storage. I try to implement it in a channel mux way which is running a mux routine to accept the cache operations like set, del, get, expire and etc. since Effective Go says "Do not communicate by sharing memory; instead, share memory by communicating."

I implemented a RWMutex version to compare, in my experiments, when I set 500000 random keys and get 250000 keys, the RWMutex is much better to Channel (857 milliseconds vs 1613 milliseconds) and also RWMutex took less memory than channels. I think the Read Lock is much better and cheaper than the Get operation queued up inside the mux goroutine. 

Any suggestions if we still like the channel mux way? Just curious about this, :)

My experiment codes can be found at https://github.com/mijia/cache
Thank you very much.

Best and Regards,
Jia Mi

--
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.
ro4tub | 19 Dec 13:51 2014
Picon

any explanation of clone function

Hi all,

I have two questions on the clone function ( code is attached at below).
1. why use 8(SP) as flags argument, instead of 0(FP)
2. How to pass the arguments to the system call clone?

Thanks,
/ro4tub


/* Prototype for the raw system call */
long clone(unsigned long flags, void *child_stack, void *ptid, void *ctid, struct pt_regs *regs);

271 // int64 clone(int32 flags, void *stack, M *mp, G *gp, void (*fn)(void));
272 TEXT runtime·clone(SB),NOSPLIT,$0
273     MOVL    flags+8(SP), DI
274     MOVQ    stack+16(SP), SI
275 
276     // Copy mp, gp, fn off parent stack for use by child.
277     // Careful: Linux system call clobbers CX and R11.
278     MOVQ    mm+24(SP), R8
279     MOVQ    gg+32(SP), R9
280     MOVQ    fn+40(SP), R12
281 
282     MOVL    $56, AX
283     SYSCALL
284 
285     // In parent, return.
286     CMPQ    AX, $0
287     JEQ 2(PC)
288     RET
289 
290     // In child, on new stack.
291     MOVQ    SI, SP
292 
293     // Initialize m->procid to Linux tid
294     MOVL    $186, AX    // gettid
295     SYSCALL
296     MOVQ    AX, m_procid(R8)
297 
298     // Set FS to point at m->tls.
299     LEAQ    m_tls(R8), DI
300     CALL    runtime·settls(SB)
301 
302     // In child, set up new stack
303     get_tls(CX)
304     MOVQ    R8, m(CX)
305     MOVQ    R9, g(CX)
306     CALL    runtime·stackcheck(SB)
307 
308     // Call fn
309     CALL    R12
310 
311     // It shouldn't return.  If it does, exit
312     MOVL    $111, DI
313     MOVL    $60, AX
314     SYSCALL
315     JMP -3(PC)  // keep exiting

--
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.
ro4tub | 19 Dec 13:29 2014
Picon

When will M or G be recycled?

Hi all,



Recently, I am learning the internal of goroutine (version: go1.3.3).
I draw the state chart of G, the last state of goroutine is Gdead and it was put on the P's gfree list or the scheduler's global gfree list.
Yes, scheduler will reuse the dead G. But I didn't find the implementation destroying G.

Neither, I didn't find the code where destroying M.

I enabled GODEBUG="schedtrace=1000,scheddetail=1".

Here is the log:
SCHED 0ms: gomaxprocs=8 idleprocs=0 threads=3 idlethreads=0 runqueue=0 gcwaiting=1 nmidlelocked=0 nmspinning=1 stopwait=1 sysmonwait=0
SCHED 1006ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 2014ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 3021ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 4031ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 5040ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 6048ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 7056ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 8064ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0
SCHED 9072ms: gomaxprocs=8 idleprocs=8 threads=11 idlethreads=8 runqueue=0 gcwaiting=0 nmidlelocked=1 nmspinning=0 stopwait=0 sysmonwait=0


Here is the test code:
http://play.golang.org/p/BjUYFeyYUN

thanks,
/ro4tub

--
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