[go-nuts] File method WriteString frequent calls led to a large system cache

2016-06-27 Thread Tamás Gulácsi
Don't Stat on every log line, but use some other mechanism (mutex, channel) to 
rotate the logs every day.

-- 
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] Re: Trouble querying REST API with net/http (api verified working with curl)

2016-06-27 Thread Kiki Sugiaman

Haha! Happens to the best of us every once in a while.


On 28/06/16 02:57, mark mellar wrote:
ksug, you were right... I was able to replicate the error using curl 
by changing the -x parameter from 'GET' to 'Get' .


How embarrassing, I'll go sit in the corner and think about what I've 
done...


Thanks for your help guys!

Mark.

On Monday, June 27, 2016 at 7:12:59 AM UTC+1, ksug wrote:

I know this is a bit late, so perhaps you don't care anymore...

Anyway, the server may not understand the "Get" method in this line:
|req, err := http.NewRequest("Get",
"https://"+host+".here.com:443/rest/json/flows
", nil)
|


On 27/06/16 08:22, mark mellar wrote:

For anyone else having similar issues, I found I was able to work
around this by using client.Get() rather than client.Do().

Still not sure what the root cause is though...

Cheers.

On Friday, June 24, 2016 at 7:32:36 AM UTC+1, mark mellar wrote:

Good tip on using httputil to inspect the request!
Unfortunately I'm not seeing anything obviously wrong...

Using curl -v

*   Trying ...
* Connected to host.here.com  ()
port 443 (#0)
* TLS 1.0 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate: host
> GET /rest/json/flows HTTP/1.1
> Host: host.here.com 
> User-Agent: curl/7.43.0
> Accept: */*
> Cookie:

connect.sid=s%3AeQ30DeGtFyrhrntWofMWpGXo.%2F745zwxR0ErYrpnoVDklkt%2F7H9FX5GfcroBFXg5M6Ag

> Content-Type: application/json


using httputil.DumpRequestOut

Get /rest/json/flows HTTP/1.1

Host: host.here.com:443 

User-Agent: Go-http-client/1.1

Content-Type: application/json

Cookie:

connect.sid=s%3A%2FWuxV7HdAnHDweXFvs4N8%2BaB.DuNDxfVN6sLhLO%2Flu3hIY7PfUnfMquyRIfXSllGtZpM

Accept-Encoding: gzip


I'm suspicious about the Accept-Encoding field. I tried
twiddling DisableCompression in my transport but nothing
changed...

Cheers,

Mark

On Friday, June 24, 2016 at 5:46:06 AM UTC+1, Tamás Gulácsi
wrote:

Just a blind shoot into the darkness: try to use one
(global) http.Client! Also, you can ask curl to dump the
request, and net/http/httputil also to compare them.

-- 
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...@googlegroups.com .
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+unsubscr...@googlegroups.com 
.

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


Re: [go-nuts] Re: formal verification in Go? someday perhaps?

2016-06-27 Thread Scott Cotton
I don't see why not either.

I think what's missing for targeting go is this:

A library taking ssa representation and producing formal representations
(formulae, transition systems, models of
parallelism,...)

I guess that may actually be many libraries, as there are many different
ways to model.  but starting out with some basics could go a long way.  bit
blasting code with no concurrency into a transition system is an obvious
starting point.
modelling the concurrency in some clean, symbolic or compact way to
represent all possible interleavings would enable lots of possibilities
downstream (spin,smt, and the go tools that are starting to show up).



2016-06-28 0:24 GMT+02:00 Daniel Skinner :

> > I think a better question is:  can go tools for formal verification
> become available?
>
> I did some research on formal verification recently, no experience
> previously. I don't really see why not. Just digging through my own code, I
> have an implementation of the simplex method which I could use to solve
> boolean and integer linear optimizations. Gonum likely has better
> optimizers up for the tasks, though i haven't looked.
>
> It just seemed like the most difficult part would be providing an
> intuitive way of defining the problem given a domain. Of course, static
> analysis is great too and you made me curious, what's missing from the `go`
> package to go that route?
>
> On Sun, Jun 26, 2016 at 3:49 PM  wrote:
>
>> I think a better question is:  can go tools for formal verification
>> become available?  The distinction is that formal verification tools can be
>> applied to
>> hardware, protocols, assembly, software, etc.   Why not do that in go?
>>
>> Most such tools are in C or C++, and the low level engines/components are
>> highly optimised.  Go can easily compete with "standard" C/C++, i.e.
>> software which has not been highly optimised.  It also provides enough
>> low-level access to be competitive against highly optimised C/C++ (e.g.
>> assembly, precision of memory representations) but it takes work.
>>
>> One of the research initiatives we are taking up is "scalable cloud
>>  architectures for formal technologies".  Basically, composable cloud
>> microservices for formal technologies like model checking, SAT/BDD/SMT,
>> theorem proving, as well as encoders for verification problems, etc, but in
>> terms of deployment in the cloud.  A related startup is satalia.  Go is a
>> natural fit for this initiative, and we already have some results with go.
>>
>> I think the biggest obstacle to formal tools targeting analysis of go
>> programs is formal representations in the golang "go" package.  Once that
>> is available, things will start to snowball.
>>
>>
>>
>>
>>
>> Le lundi 9 mars 2015 01:07:36 UTC+1, Camilo Aguilar a écrit :
>>>
>>> I ran across this post today:
>>> http://blog.adacore.com/testing-static-formal. Basically, showing how
>>> you can do formal verifications in ADA2012. Is it realistic to think that a
>>> feature like that would someday arrive to 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.
>>
>


-- 
Scott Cotton
President, IRI France SAS
http://www.iri-labs.com

-- 
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: Best practice when putting large amounts of functionality behind an interface

2016-06-27 Thread Chad
What does the interface look like currently?

On Monday, June 27, 2016 at 10:54:31 PM UTC+2, Tyler Compton wrote:
>
> Right now, I have a web server with an interface that defines methods for 
> every kind of database read/write operation my application has. 
>
Any example ?
 

> Unsurprisingly, it's pretty large for a Go interface at around 30 methods. 
> I originally did this because I wanted to be able to support multiple 
> implementations of my database layer, but now it's only so that I can mock 
> out this functionality for testing, which is still important to me.
>
> This works fine, but it doesn't /feel/ right, whatever that means. As the 
> proverb goes, "the bigger the interface, the weaker the abstraction." To be 
> fair, I'm not really going for a lot of abstraction here. The only objects 
> that should implement this interface would be geared very heavily towards 
> my needs. Maybe that's where I went wrong.
>
> Is there a more idiomatic way I could be doing this?
>

Interfaces are composable so you could probably make a slight refactor 
where you assemble methods by usage. It may help keep things clearer. 

-- 
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] 'go tool pprof' only shows "Type: CPU" and not a callgraph

2016-06-27 Thread Dave Cheney
What are the exact commands you used?

It is easy to misuse proof, here is a slide with some of the gotchas.

http://talks.godoc.org/github.com/davecheney/presentations/writing-high-performance-go.slide#11

-- 
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] Question - type assertion x.(*T)

2016-06-27 Thread michaelwain1990
Hi,

Reading through gaoling spec regarding type assertions, in some code I've 
see type assertions like:
a := x.(*T)

i don't see a mention of that syntax in the spec, what is it doing?

-- 
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] Best practice when putting large amounts of functionality behind an interface

2016-06-27 Thread Tyler Compton
Right now, I have a web server with an interface that defines methods for 
every kind of database read/write operation my application has. 
Unsurprisingly, it's pretty large for a Go interface at around 30 methods. 
I originally did this because I wanted to be able to support multiple 
implementations of my database layer, but now it's only so that I can mock 
out this functionality for testing, which is still important to me.

This works fine, but it doesn't /feel/ right, whatever that means. As the 
proverb goes, "the bigger the interface, the weaker the abstraction." To be 
fair, I'm not really going for a lot of abstraction here. The only objects 
that should implement this interface would be geared very heavily towards 
my needs. Maybe that's where I went wrong.

Is there a more idiomatic way I could be doing this?

-- 
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: database proxy ?

2016-06-27 Thread Tamás Gulácsi
Why do you need such a thing? gopkg.in/rana/ora.v3 (esp. the current master 
branch) has a simple Pool implementation for reusing connections - but no 
connection limit.
Oracle does have a SessionPool implementation, but haven't used it yet.

Otherwise, database/sql/driver is quite limited, you could create an gRPC proxy 
for it easily.

-- 
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: Shuffle Items in a Slice

2016-06-27 Thread Chris Hines
The history of this behavior is explained in the release notes for Go 
1.3: https://golang.org/doc/go1.3#map

On Friday, June 24, 2016 at 8:48:20 AM UTC-4, Val wrote:
>
> 2 implementations here : 
> http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go
>
> As for the map iteration trick, the runtime doesn't guarantee to randomize 
> anything, although it often tries to, so developers don't rely on some 
> specific order. I've seen (in the past) some map iterations consistently 
> not randomized at all. This behaviour may have evolved, but don't rely on 
> it.
>
>
> On Friday, June 24, 2016 at 1:05:49 PM UTC+2, dc0d wrote:
>>
>> Hi;
>>
>> To shuffle items in a slice I'm doing this:
>>
>> var res []Item
>>
>> //fill res logic
>>
>> shuffle := make(map[int]*Item)
>> for k, v := range res {
>>  shuffle[k] = 
>> }
>> res = nil
>> for _, v := range shuffle {
>>  res = append(res, *v)
>> }
>>
>> Which inserts items into a map then ranges over that map. Ranging over a 
>> map in Go returns the items in random order.
>>
>> 1 - I thought it's a cool trick!
>> 2 - Is anything bad about doing this?
>>
>

-- 
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: database proxy ?

2016-06-27 Thread Caleb Doxsey
For postgres use pgbouncer. For mysql there's youtube's vitess.

On Monday, June 27, 2016 at 12:24:32 PM UTC-4, Tieson Molly wrote:
>
>
> Are there any existing packages or libraries that implement a generic 
> database/sql proxy?
>
> My goal was to create a small service that connected to the database and 
> implemented a connection pool.
>
> Then other services would proxy their database/sql calls to this service 
> rather than make their own connection to the database.
>
>
> Best regards,
>
> Ty
>

-- 
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: x/mobile: How to generate a builtin error type binding by gobind command?

2016-06-27 Thread Elias Naur
You can't, at least not yet. The use of the builtin error type is an 
implementation detail of CL 24100 which is about how errors and exceptions 
are represented in the generated bindings. The CL does make the path toward 
exposing error to the native languages easier in the future.

 - elias

On Monday, June 27, 2016 at 4:16:40 PM UTC+2, tenntenn wrote:
>
> Hi, all.
>
> In order to understand how gomobile bind works, I tried to run commands 
> (gobind, go build and etc.) step by step.
> But I could not generate a builtin error type binding by gobind command.
> This change makes to be able to generate builtin error type bindings by 
> gomobile bind command.
> https://go-review.googlesource.com/#/c/24100/
>
> How can I generate a builtin error type binding by gobind command?
> I think that gobind command also should be fixed to accept nil package 
> (universe scope).
>
> 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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] TLS

2016-06-27 Thread Sam Whited
On Mon, Jun 27, 2016 at 9:42 AM, Konstantin Khomoutov
 wrote:
> Sure, the standard package crypto/tls has tests, and your installation
> of Go comes with full source code of the Go standard library.

Reading the source is not the same as documentation or examples;
please don't confuse the two. This is an easy way to drive away new
users who may not have the experience to be digging around in the
standard library source (no matter how accessible it is).

> On Mon, 27 Jun 2016 20:04:52 +0600 Oleg Puchinin  
> wrote:
> Mybe you have simple sample for my ?
> Server and client initialization.

If you look at the documentation for the tls.Dial method
(https://godoc.org/crypto/tls#Dial) there is an "Example" link just
below the method description.

—Sam


-- 
Sam Whited
pub 4096R/54083AE104EA7AD3
https://blog.samwhited.com

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

2016-06-27 Thread Konstantin Khomoutov
On Mon, 27 Jun 2016 20:04:52 +0600
Oleg Puchinin  wrote:

> Thank you, Dave !
> Mybe you have simple sample for my ?
> Server and client initialization.

Sure, the standard package crypto/tls has tests, and your installation
of Go comes with full source code of the Go standard library.

-- 
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] Trying to dynamically find interfaces

2016-06-27 Thread Jan Mercl
On Mon, Jun 27, 2016 at 4:16 PM David Koblas  wrote:

type BaseAppController struct {
*Application
IGet
IList
}

The above means that every instance of BaseAppController satisfies both the
IGet and IList interfaces and that is known statically at compile time. I
don't understand why the code tests for that at run time. However, beware
that even though the interface is implemented by embedding a field of an
interface type, without setting that field to something actually handling
the method call you will get the panic(s) as you described.

"Subclasses" and parent/child type relations make little sense in Go
because composition is not inheritance. Yes, the methods of embedded fields
are merged to the method set of the embedding struct, but there the story
ends. Method set per se does not handle any actual method calls. There must
be always a real instance of a specific type that has the method. Note:
typed nil is a real instance of a type that can handle method calls, as
long as it does not try to dereference its receiver. But the zero value of
an embedded interface is not a real instance of any specific type.

-- 

-j

-- 
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] x/mobile: How to generate a builtin error type binding by gobind command?

2016-06-27 Thread tenntenn
Hi, all.

In order to understand how gomobile bind works, I tried to run commands 
(gobind, go build and etc.) step by step.
But I could not generate a builtin error type binding by gobind command.
This change makes to be able to generate builtin error type bindings by 
gomobile bind command.
https://go-review.googlesource.com/#/c/24100/

How can I generate a builtin error type binding by gobind command?
I think that gobind command also should be fixed to accept nil package 
(universe scope).

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


[go-nuts] Trying to dynamically find interfaces

2016-06-27 Thread David Koblas
I've got a program that is trying to implement functions on "subclasses", 
where the parent can check to see if the interface is implemented. For 
perspective, it's really dealing with REST URL generation based on if 
methods exist.

What I'm running into is that based on the following pattern, both the 
IList and IGet interfaces are found on the TestController object, when only 
1 is implemented. When the IGet interface is called I get a panic.

I would rather not make concrete definitions of the Get/List on the base 
struct and then have to override them, would much rather do the test for 
existence then go from there.

Code is available on the playground --  https://play.golang.org/p/5j58fejeJ3

package main

import "fmt"

type IGet interface {
Get(int)
}

type IList interface {
List(int)
}

type Application struct {
namestring
}

type BaseAppController struct {
*Application

IGet
IList
}

type TestController struct {
*BaseAppController
}

func (ctrl *BaseAppController) Init() {
fmt.Println("In Init")

if f, ok := interface{}(ctrl).(IGet); ok {
fmt.Println("Controller Found GET", f)
} else {
fmt.Println("Controller NOT Found GET", f)
}

if f, ok := interface{}(ctrl).(IList); ok {
fmt.Println("Controller Found LIST", f)
} else {
fmt.Println("Controller NOT Found LIST", f)
}
}

func (ctrl *BaseAppController) Call() {
fmt.Println("In Call")

if f, ok := interface{}(ctrl).(IGet); ok {
fmt.Println("Controller Found GET - going to call", f)

f.Get(7)
} else {
fmt.Println("Controller NOT Found GET - can't call", f)
}
}

// Test controller implements the Get Method
func (ctrl *TestController) Get(v int) {
fmt.Printf("Hi name=%s v=%d\n", ctrl.name, v)
}

func main() {
app := Application{"hithere"}
ctrl := TestController{{Application: }}

ctrl.Init()

ctrl.Call()
}

-- 
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] File method WriteString frequent calls led to a large system cache

2016-06-27 Thread feng19910104
*go code*

package main

import (
"fmt"
"net/http"
"os"
"time"
)

var logCtxCh chan *http.Request
var accessLogFile *os.File

type HandlerHttp struct{}

func (this *HandlerHttp) ServeHTTP(w http.ResponseWriter, req *http.Request) {
sendAccessLog(req) 
w.Write([]byte("Hello Word"))
}

func main() {
s := {
Addr:":8012",
Handler: {},
}
logCtxCh = make(chan *http.Request, 500)
go startAcessLog()

   err:= s.ListenAndServe()
   fmt.Println(err.Error())
}

func startAcessLog() {
for {
select {
case ctx := <-logCtxCh:
handleAccessLog(ctx)
}
}
}

func sendAccessLog(req *http.Request) {
logCtxCh <- req
}

func handleAccessLog(req *http.Request) {
uri := req.RequestURI
ip := req.RemoteAddr
agent := req.UserAgent()
refer := req.Referer()
method := req.Method
now := time.Now().Format("2006-01-02 15:04:05")

logText := fmt.Sprintf("%s %s %s %s %s %s\n",
now,
ip,
method,
uri,
agent,
refer,
)

fileName := fmt.Sprintf("/data/logs/zyapi/access_zyapi%s.log",
time.Now().Format("2006010215"),
)
writeLog(fileName, logText)
}

func writeLog(fileName, logText string) {
var err error
var exist = true

if _, err = os.Stat(fileName); os.IsNotExist(err) {
exist = false
}

if exist == false {
if accessLogFile != nil {
accessLogFile.Sync()
accessLogFile.Close()
}

accessLogFile, err = os.OpenFile(fileName, 
os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err == nil {
_, err = accessLogFile.WriteString(logText)
}
if err != nil {
fmt.Errorf(err.Error())
}
} else {
if accessLogFile == nil {
accessLogFile, err = os.OpenFile(fileName, os.O_WRONLY|os.O_APPEND, 
0666)
if err != nil {
fmt.Errorf(err.Error())
return
}
}
_, err = accessLogFile.WriteString(logText)
if err != nil {
fmt.Errorf(err.Error())
}
}
}





Reproduction:

ab -n10 -c10 -k "http://127.0.0.1:8012/;
ab -n10 -c10 -k "http://127.0.0.1:8012/;
ab -n10 -c10 -k "http://127.0.0.1:8012/;
ab -n10 -c10 -k "http://127.0.0.1:8012/;
ab -n10 -c10 -k "http://127.0.0.1:8012/;



After running several times the system file cache becomes very large

CONTAINERCPU % MEM USAGE / LIMIT MEM % NET I/O 
BLOCK I/O
zyapi_801138.47%6.442 GB / 6.442 GB   100.00%  0 B / 0 B   0 B 
/ 115.4 MB
zyapi_801236.90%6.442 GB / 6.442 GB   99.99%   0 B / 0 B   0 B 
/ 115.6 MB





-- 
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] Example to write web application in golang doc needs to be corrected

2016-06-27 Thread madhusudhan . sitcs
Hi All,

Example to write web application 
https://golang.org/doc/articles/wiki/#tmp_10 
https://golang.org/doc/articles/wiki/final.go needs to be corrected to fix 
an error leading to 'http: multiple response.WriteHeader calls'.

In the renderTemplate() func if there is an error while exectuing the line 
templates.ExecuteTemplate(w, tmpl+".html", p) then the example suggests to 
return error using http.Error().

But we have passed ResponseWriter obj to templates.ExecuteTemplate() and 
the first call to Write on this obj will trigger an implicit 
WriteHeader(http.StatusOK). http.Error() will also write the Header and we 
get the error.


Regards,
--Madhu C S

-- 
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] Are there any gmail imap golang WORKING sample ?

2016-06-27 Thread emersion
The preferred method to login to Gmail's IMAP & SMTP server is with SASL 
XOAUTH2. You should use it instead of app-specific passwords.

On Tuesday, March 17, 2015 at 2:35:56 PM UTC+1, Hugo Schmitt wrote:
>
> If anyone arrives at this in 2015, for connecting in Gmail I had two 
> surprises:
>
> 1- Must use app specific password
> 2- Imap address must be imap.gmail.com:993
>
> On Sunday, September 15, 2013 at 11:37:59 AM UTC-3, Maxim Khitrov wrote:
>>
>> Perhaps this might help: 
>>
>>
>> http://developers.google.com/gmail/imap_extensions#special-use_extension_of_the_list_command
>>  
>>
>> On Sun, Sep 15, 2013 at 9:12 AM, Alexander Prihodko 
>>  wrote: 
>> > Thank you for the answer. 
>> > Package definitely works for me. 
>> > My problem is in gmail label's name. Somewhat i cannot reach 
>> [GMAIL]/Spam 
>> > folder. 
>> > But it's not about golang and imap implementation which works 
>> perfectly. 
>> > Thank s a lot! 
>> > 
>> > -- 
>> > Alex 
>> > 
>> > 
>> > 2013/8/29 Maxim Khitrov  
>> >> 
>> >> The line numbers in the stack trace don't match the attached file, but 
>> >> I'll assume that 81 refers to "return c.Mailbox.Messages, nil". It 
>> >> probably panics because c.Mailbox is nil at that point, perhaps 
>> >> because the Select command failed. You need to check for errors to 
>> >> figure out what the problem is. Turning on protocol logging is also 
>> >> helpful. 
>> >> 
>> >> You can run my demo script with your gmail account to verify that the 
>> >> package is working: 
>> >> 
>> >> http://code.google.com/p/go-imap/source/browse/go1/imap-demo/demo1.go 
>> >> 
>> >> 
>> http://code.google.com/p/go-imap/source/browse/go1/imap-demo/demo1-gmail.txt 
>> >> 
>> >> On Thu, Aug 29, 2013 at 10:41 AM, Alexander Prihodko 
>> >>  wrote: 
>> >> > Hello Maxim 
>> >> > 
>> >> > Slightly modified my code to join it to single file and remove 
>> >> > credentials 
>> >> > (attached). It was working before :-( 
>> >> > It authenticates, but unable to pull messages. 
>> >> > 
>> >> > $ go run check_mailbox_imap.go 
>> >> > Server says hello: Gimap ready for requests from xxx.xx.xx.xx 
>> >> > v??.42 
>> >> > 
>> >> > Mailbox status: 
>> >> > panic: runtime error: invalid memory address or nil pointer 
>> >> > dereference 
>> >> > [signal 0xb code=0x1 addr=0x1 pc=0x80491f0] 
>> >> > 
>> >> > goroutine 1 [running]: 
>> >> > main.CheckMailBox(0x81b5f38, 0x5, 0x81ccf88, 0x14, 0x81c1288, ...) 
>> >> > 
>> /home/al/workspace/go/src/scripts/amx/check_mailbox_imap.go:81 
>> >> > +0x400 
>> >> > main.main() 
>> >> > 
>> /home/al/workspace/go/src/scripts/amx/check_mailbox_imap.go:33 
>> >> > +0x53 
>> >> > 
>> >> > goroutine 2 [syscall]: 
>> >> > exit status 2 
>> >> > 
>> >> > 
>> >> > Any ideas? Than you! 
>> >> > 
>> >> > 
>> >> > Alex 
>> >> > 
>> >> > 
>> >> > 2013/8/28 Maxim Khitrov  
>> >> >> 
>> >> >> On Wed, Aug 28, 2013 at 11:41 AM,   wrote: 
>> >> >> > google.com/p/go-imap/go1 stopped working couple months ago, 
>> >> >> 
>> >> >> News to me. What about it isn't working? 
>> >> > 
>> >> > 
>> > 
>> > 
>>
>

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

2016-06-27 Thread Oleg Puchinin
Thank you, Dave !
Mybe you have simple sample for my ?
Server and client initialization.

Oleg.

2016-06-27 16:53 GMT+06:00 Dave Cheney :

> tls.Dial is what you should use. It's the same as net.Dial, except it
> expects the remote end to speak TLS.
>
> On Monday, 27 June 2016 20:48:06 UTC+10, Oleg Puchinin wrote:
>>
>> I want connect to my TCP server from my client use tls.
>>
>> 2016-06-27 16:44 GMT+06:00 Dave Cheney :
>>
>>> If you want to make a connection to a server take speaks TLS, you can
>>> use https://godoc.org/crypto/tls#Dial
>>>
>>> If you want to make a connection to a web server that uses HTTPS, the
>>> net/http package does this automatically for you.
>>>
>>> If you can share some more details about what you are trying to do, we
>>> can probably give a better suggestion.
>>>
>>> Thanks
>>>
>>> Dave
>>>
>>> On Monday, 27 June 2016 20:27:41 UTC+10, Oleg Puchinin wrote:

 Hello !
 How to start use tls for TCP connection ?

 Oleg.

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


Re: [go-nuts] golang poll/epoll/select

2016-06-27 Thread Michael Soulier
On Saturday, June 25, 2016 at 9:03:59 PM UTC-4, Michael Soulier wrote:
>
> Hmm. Maybe I misunderstand how runsv connects the two. A simple shell test 
> seems to behave more as expected. I'll need to dig.
>
>
I think I found it. On read I'm getting "resource temporarily unavailable", 
so I suspect runsv has set stdin to be non-blocking.

select() is the only way I know of to work with a non-blocking file 
descriptor. Now if I can only get select to work.

Mike 

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

2016-06-27 Thread Oleg Puchinin
I want connect to my TCP server from my client use tls.

2016-06-27 16:44 GMT+06:00 Dave Cheney :

> If you want to make a connection to a server take speaks TLS, you can use
> https://godoc.org/crypto/tls#Dial
>
> If you want to make a connection to a web server that uses HTTPS, the
> net/http package does this automatically for you.
>
> If you can share some more details about what you are trying to do, we can
> probably give a better suggestion.
>
> Thanks
>
> Dave
>
> On Monday, 27 June 2016 20:27:41 UTC+10, Oleg Puchinin wrote:
>>
>> Hello !
>> How to start use tls for TCP connection ?
>>
>> Oleg.
>>
> --
> 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.
>

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

2016-06-27 Thread Dave Cheney
If you want to make a connection to a server take speaks TLS, you can 
use https://godoc.org/crypto/tls#Dial

If you want to make a connection to a web server that uses HTTPS, the 
net/http package does this automatically for you.

If you can share some more details about what you are trying to do, we can 
probably give a better suggestion.

Thanks

Dave

On Monday, 27 June 2016 20:27:41 UTC+10, Oleg Puchinin wrote:
>
> Hello !
> How to start use tls for TCP connection ?
>
> Oleg.
>

-- 
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] my own lib

2016-06-27 Thread Oleg Puchinin
Hello !
How do I publish my project right? One file for now.

https://sourceforge.net/projects/opgolib/?source=navbar

Oleg

-- 
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] Shuffle Items in a Slice

2016-06-27 Thread Martin Geisler
On Fri, Jun 24, 2016 at 2:54 PM, Val  wrote:
> The playground caches everything, so running multiple times the same program
> will just serve the previously generated output.

Thanks, that's good to know! Makes a lot of sense too.

> Also in the playground everything is frozen at some point in the past : the
> clock, the randomness sources, and you can't make outgoing requests to
> import randomness from the network.

I found this blog post with a lot more background information:

  https://blog.golang.org/playground

-- 
Martin Geisler

-- 
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] Re: Shuffle Items in a Slice

2016-06-27 Thread Martin Geisler
Hi Val

On Fri, Jun 24, 2016 at 2:48 PM, Val  wrote:
> 2 implementations here :
> http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go
>
> As for the map iteration trick, the runtime doesn't guarantee to randomize
> anything, although it often tries to, so developers don't rely on some
> specific order.

That's a nice feature and very helpful when writing tests... otherwise
you end up with a test that works fine on one version/architecture and
"suddenly" breaks later.

Randomizing the order "on purpose" is probably also done for security
reasons. Python works much the same, and some years ago, the CPython
VM began randomizing the dict (map) type. The problem was that
carefully crafted input would trigger a worst-case scenario in the
hash table used behind the scenes and suddenly make your server crawl
to a halt.

The input could be HTTP headers, for example, with carefully chosen
names: these are normally read from the client and used as keys in a
map. With the right keys, you can trigger hash collisions and make the
map allocate much more memory than you would expect with typical keys.

Having the runtime add a bit of randomness to the keys prevents this
scenario. When the randomness changes at every execution, it further
helps the developers by highlighting the nondeterministic iteration
order of the hash table.

> I've seen (in the past) some map iterations consistently not
> randomized at all. This behaviour may have evolved, but don't rely on it.

That's good advice :-)

-- 
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] Re: Trouble querying REST API with net/http (api verified working with curl)

2016-06-27 Thread Kiki Sugiaman

I know this is a bit late, so perhaps you don't care anymore...

Anyway, the server may not understand the "Get" method in this line:
|req, err := http.NewRequest("Get", 
"https://"+host+".here.com:443/rest/json/flows;, nil)

|


On 27/06/16 08:22, mark mellar wrote:
For anyone else having similar issues, I found I was able to work 
around this by using client.Get() rather than client.Do().


Still not sure what the root cause is though...

Cheers.

On Friday, June 24, 2016 at 7:32:36 AM UTC+1, mark mellar wrote:

Good tip on using httputil to inspect the request! Unfortunately
I'm not seeing anything obviously wrong...

Using curl -v

*   Trying ...
* Connected to host.here.com  () port
443 (#0)
* TLS 1.0 connection using TLS_DHE_RSA_WITH_AES_256_CBC_SHA
* Server certificate: host
> GET /rest/json/flows HTTP/1.1
> Host: host.here.com 
> User-Agent: curl/7.43.0
> Accept: */*
> Cookie:

connect.sid=s%3AeQ30DeGtFyrhrntWofMWpGXo.%2F745zwxR0ErYrpnoVDklkt%2F7H9FX5GfcroBFXg5M6Ag

> Content-Type: application/json


using httputil.DumpRequestOut

Get /rest/json/flows HTTP/1.1

Host: host.here.com:443 

User-Agent: Go-http-client/1.1

Content-Type: application/json

Cookie:

connect.sid=s%3A%2FWuxV7HdAnHDweXFvs4N8%2BaB.DuNDxfVN6sLhLO%2Flu3hIY7PfUnfMquyRIfXSllGtZpM

Accept-Encoding: gzip


I'm suspicious about the Accept-Encoding field. I tried
twiddling DisableCompression in my transport but nothing changed...

Cheers,

Mark

On Friday, June 24, 2016 at 5:46:06 AM UTC+1, Tamás Gulácsi wrote:

Just a blind shoot into the darkness: try to use one (global)
http.Client! Also, you can ask curl to dump the request, and
net/http/httputil also to compare them.

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


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