amit.lavon | 30 Jul 21:15 2014
Picon
Picon

gzip.Writer.Close() documentation doesn't mention flushing

The doc says: Close closes the Writer. It does not close the underlying io.Writer.

I was concerned whether it flushes or not (should be mentioned either way). I had to go over the code to realize that it does.

I'd like to ask if this piece of information can be added to the function's doc. Can it?

Cheers :)
Amit

--
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.
Joel Reymont | 30 Jul 20:44 2014
Picon

Non-XMPP message server

I'd like to clone ejabberd, more or less, and do it in Go.

I'd like to use Google Protobuf instead of XML (XMPP) or JSON, though, as this would be most power-saving on mobile devices. 

Does it make sense to invent a better message server wheel at this point?

    Thanks, Joel

--
http://wagerlabs.com/about

--
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.
Luke Mauldin | 30 Jul 19:45 2014
Picon

XML Namespace Issue

All,

I am having a problem decoding an XML string with namespaces.  See: http://play.golang.org/p/jmtemSB5ir
I would like the XML decoded into the Attachments slice on line 21 but the slice is always empty.  The text appears if I uncomment line 20.  How can I get the Attachments to correctly decode with the namespace?

Luke

--
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.
Roberto García López | 30 Jul 19:22 2014
Picon

Getting a repository hosted at bitbucket.org using Windows 8

Hi there,

I'm trying to use "go get" to download a remote repository hosted at bitbucket.org in a PC using Windows 8. Here's the command line

go get bitbucket.org/vcrobe/privatetest.git

(The repository is publicly available)

But I get the following error:

package bitbucket.org/vcrobe/privatetest.git: invalid version control suffix in bitbucket.org/ path

Can someone tell me the correct command to download the repository?

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.
Steve McCoy | 30 Jul 18:55 2014
Picon

Re: go get remote.host/<something>.git

I'm surprised by this behavior, because the typical git repository URL *is* something ending in .git, and "go get host/thing/repo" is normally able to figure out that it should use "git clone https://host/thing/repo.git" (or git:// etc.), and this is the documented behavior that you mentioned in your first post. However, this is also a repo that isn't one of bitbucket, github, google, or launchpad, so you need to either use the explicit .git or for the URL to point to a web page with the appropriate meta tag. Assuming that Stash doesn't give you a way to provide the latter, it looks like Jesse is right, and you'll need to use "stash.host/project/repo.git.git" 

If you manually clone the Stash repo with the git command, what URL do you have to use?


On Wed, Jul 30, 2014 at 4:49 AM, Stanislav Seletskiy <s.seletskiy-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
It fails, because of in that case it think that package located in the
local dir (e.g., in the $GOPATH/stash.host/project/repo).

On Tue, Jul 29, 2014 at 10:03 PM, Steve McCoy <mccoyst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> For the sake of my curiosity, what happens if you run `go get
> stash.host/project/repo`?
>
>
> On Monday, July 28, 2014 7:54:33 AM UTC-4, s.sel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
>>
>> I'm using Git hosting software called Atlassian Stash and I just can't
>> help `go get` to love `stash`.
>>
>> It's necessary for `stash` to have repo URLs ending with `.git`, so you
>> can't clone repo if it path is not ending on `.git`.
>>
>> However, if I trying to do `go get stash.host/project/repo.git`, I'm
>> getting failure. After stracing `go get` command I've figured out that it's
>> cutting out `.git` ending and requesting just `/project/repo` from server,
>> which `stash` can't serve.
>>
>> It looks like issue in `go get` for me, because of in the docs
>> (http://golang.org/cmd/go/#hdr-Remote_import_paths) I see following:
>>
>>> For example, import "example.org/user/foo.hg" denotes the root directory
>>> of the Mercurial repository at example.org/user/foo or foo.hg
>>
>>
>> Key phrase here is "foo or foo.hg".
>>
>> So shouldn't `go get` try both URLs with `.git` and without `.git` on the
>> end?



--
Stanislav Seletskiy

--
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.
Sam Boyer | 30 Jul 18:10 2014
Picon

Method sets for method values

this might seem a little odd, as it's definitely the product of coding until sunrise. is it possible to bind methods to method values? basically, i want to make this work:

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

i've tried a couple different approaches and none of them will compile, because (i believe) the method value is an unnamed type, but my stateEnumerator is a named type (http://golang.org/ref/spec#Type_identity). sure, there are other ways i could accomplish this - just make a sorta implicitly monadic function that takes the method value as an argument, and call it that way. or call it via a method expression.

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

thing is, both of those are more awkward than my original intended form, which i think is is nifty because it allows humans to read, left to right, the pipeline of operations that will be performed. in the right case, it could make for some nice APIs.

so - is there any tricksy way of making my preferred form work?

--
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.
Luke Mauldin | 30 Jul 14:00 2014
Picon

JSON Unmarshal Question

All,

I have a JSON string that I'd like to Unmarshal: http://play.golang.org/p/3HRJ0U55wk

In the example, the result is that both of the "fields" get unmarshalled into their own map[string]interface{}. I would prefer to use the FieldMeta struct but the incoming JSON has each of the fields as its own object instead of the fields as an array.  I do not have control over the format of the incoming JSON string.  Is there any way I can achieve the desired unmarshalling?

Luke

--
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.
Fumin Wang | 30 Jul 07:49 2014
Picon

Re: Re: Does anyone use package context from go.net?

Hi Caleb

I see, thanks for your example. This also explains the emphasis on the term "interface type" in the phrase in the first line of the type assertions section in the spec http://golang.org/ref/spec#Type_assertions , which I obviously didn't fully appreciate.
In other words, there is indeed a reason why the type of the first argument of the context.Value function

Value(key interface{}) interface{}

has to be "interface{}". This is to facilitate namespaces for keys from different packages through the type information in an "interface{}" value.
Thanks a lot Andrew and Caleb for this opportunity in teaching me another concept in Go!


On Wed, Jul 30, 2014 at 1:39 PM, Caleb Spare <cespare <at> gmail.com> wrote:
On Tue, Jul 29, 2014 at 10:08 PM, Fumin Wang <awawfumin <at> gmail.com> wrote:
> Hi Andrew
>
> Great advice, thanks!
>
> By the way, how does this type base approach compare to the int base
> approach described in the blog post:
>
> "type appengineContext struct{}" VS "type key int"
>
> I see that both approaches are immune to collisions:
>
> * Somehow Go knows that the types packageA.key and packageB.key are
> different even though they are both defined as "type packageA int; const
> aKey packageA = 0" and "type packageB int; const bKey packageB  = 0". I
> wrote a simple test and confirmed that ctx.Value() could differentiate
> between "aKey" and "bKey" even though both are "0".
>
> * Similarly, if "type packageA struct{}" and "type packageB struct{}", then
> packageA{} and packageB{} are different to the extent that "packageA{} ==
> packageB{}" won't even compile.
>
> I actually have a hard time wrapping my mind around these results. For the
> moment, the explanation I give myself is that even though "var s struct{}{};
> unsafe.Sizeof(s)" equals 0, "s" still consumes memory that holds information
> about its type. It is this extra information that "ctx.Value()" uses to
> differentiate between keys that are of the same value but of the different
> type. I wonder is this a faithful explanation?

s does indeed consume 0 bytes. But what you store in the map is not s,
directly; it is an interface{} value containing s. That stores the
type information for you.

This might make things clearer:

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

>
>
> On Wednesday, 30 July 2014 12:12:53 UTC+8, Andrew Gerrand wrote:
>>
>> Yes, essentially this, except we use a unique key for the appengine
>> Context.
>>
>> Put this in a package somewhere:
>>
>> type appengineContext struct{}
>>
>> func WithAppEngine(parent Context, c appengine.Context) Context {
>> return context.WithValue(parent, appengineContext{}, c)
>> }
>>
>> func AppengineContext(ctx Context) (appengine.Context, bool) {
>> c, ok := ctx.Value(appengineContext{}).(appengine.Context)
>> return c, ok
>> }
>>
>> It's conceivable that we'll add this to the go.net/context package at some
>> point.
>>
>> Andrew
>>
>>
>> On 30 July 2014 13:39, Fumin Wang <awaw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>>>
>>> I wonder what's the best practice for incorporating an appengine.Context
>>> into a context.Context? Is it a common practice at Google to always do
>>> something like
>>>
>>> func handleSearch(w http.ResponseWriter, r *http.Request) {
>>>
>>>   var (
>>>
>>>     ctx context.Context
>>>
>>>     cancel context.CancelFunc
>>>
>>>   )
>>>
>>>   // initialize ctx
>>>
>>>   c := appengine.NewContext(r)
>>>
>>>   context.WithValue(ctx, "appengineContext", c)
>>>
>>>   // ...
>>>
>>> }
>>>
>>>
>>> at the very start of a http.Handler to carry the appengine.Context
>>> around?
>>>
>>> By the way, thanks a lot for this great package and blog post!
>>>
>>> On Monday, 30 June 2014 10:19:31 UTC+8, Daniel Bryan wrote:
>>>>
>>>> I came across package context while trawling through the Go wiki:
>>>>
>>>> https://godoc.org/code.google.com/p/go.net/context
>>>>
>>>> It looks pretty cool - a (blessed?) way to handle cancellation and
>>>> timeouts between packages.
>>>>
>>>> Even the larger open source Go projects tend to solve this problem very
>>>> differently. When I've needed something more reliable than ad hoc solutions
>>>> with semaphore channels and sync.WaitGroup, I've previously solved it with
>>>> package tomb:
>>>>
>>>> http://godoc.org/launchpad.net/tomb
>>>>
>>>> But that only gets you so far. This package seems to have pretty simple,
>>>> universal semantics for cancelling requests (and therefore telling
>>>> goroutines to shut down, etc.)
>>>>
>>>> So I'm curious: why have I never seen this package mentioned before? Do
>>>> people use it? Is it considered dated?
>>>
>>> --
>>> 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...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
> --
> 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.

--
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.
mattn | 30 Jul 05:06 2014
Picon

[ANN] go-colorable: Colorable stdout/stderr for windows

Hi, list.

I put new small project go-colorable on github.

https://github.com/mattn/go-colorable

Most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But I don't want.)
So I wrote Writer interface that handle escape sequence for ansi color.

To use this, it's very simple.

    // Just add this line
    logrus.SetOutput(colorable.NewColorableStdout())

    logrus.Info("succeeded")
    logrus.Warn("not correct")
    logrus.Error("something error")
    logrus.Fatal("panic")

If you have any problem, please file the issue on github.

BTW, Unfortunately, it couldn't overwrite os.Stdout by this writer. :-(

Thanks.
- mattn

--
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.
lqt641 | 30 Jul 04:05 2014
Picon

:= works unnormally in a loop

Hi, everyone, I am new to golang. I use the following program to test a function, but it seems that something goes wrong:


package main
import "fmt"

func main() {

pos := 0
for i := 0; i < 10; i++ {
pos := next(pos)
fmt.Println( pos)
}


}

func next (i int) int {
return i + 1
}


The program can be compiled successfully, but its running result are all 1, why?
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.
Tyler Compton | 30 Jul 02:46 2014
Picon

Platform-specific constants without preprosessors

I'm writing a window creation and input management library similar to GLFW. So far, I've written the library so that general platform-agnostic functions are written in Go, and call C functions that are implemented in separate files, depending on the environment. Different C files are included depending on the target operating system, using C preprocessor macros like #ifdef _WIN32

This works really well for functions, but I'm not sure how to go about this with constants. I was originally planning to have constants implemented in the separate C files, and then set the Go constants to be the same as the C constants. Something like this:

windows_os.c:
const int KeyLeft=VK_LEFT;
const int KeyRight=VK_RIGHT;
const int KeyUp=VK_UP;
const int KeyDown=VK_DOWN;
[etc]

library.go
const (
   
KeyLeft=C.KeyLeft
   
KeyRight=C.KeyRight
   
KeyUp=C.KeyUp
   
KeyDow=C.KeyDown
   
[etc]
)

This doesn't work, however, probably because C constants are evaluated too late in the build process to be considered constant by Go code (right?). So what are my alternatives for creating constants that differ from platform to platform? 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.

Gmane