Re: [go-nuts] SSL socket listener

2020-06-03 Thread Dimas Prawira
Here is an example running server with TLS

package main
import (
"net/http"
"log"
)
func HelloServer(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte("This is an example server.\n"))
}
func main() {
http.HandleFunc("/hello", HelloServer)
err := http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}


so in http package there is "ListenAndServeTLS" which can be used to run
the server with TLS enabled.

Hope that helps



On Wed, Jun 3, 2020 at 2:20 PM 'Wesley Peng' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> Hello,
>
> How do I program with SSL to make a server listen on specific port which
> accepts SSL transfer only?
>
> Is there any guide for this since I have no experience on SSL socket
> programming.
>
> Thanks.
>
> Wesley Peng
> wesleyp...@aol.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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/1690752345.1320667.1591168756241%40mail.yahoo.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Bp%2BMUenJBMsZHQ-hajr1b7Leq6vGLcAJ%3DJ_vNObj9NNEsV0aw%40mail.gmail.com.


Re: [go-nuts] Assignment of pointer values in a struct...

2020-06-03 Thread Ian Lance Taylor
On Wed, Jun 3, 2020 at 7:33 PM Trig  wrote:
>
> I posted this question the other day and don't see it (may have posted from 
> another gmail account and it's still pending approval)... so here I am again.
>
> Let's say I have something like below:
> type (
>Person struct {
>   FirstName *string
>}
> )
>
> Usually, I see something like the following when assigning:
> fn := "John"
> _ = Person{
>   FirstName: ,
> }
>
> Would something like the following be alright and acceptable practice:
> _ = Person{
>   FirstName: pString("John")
> }
>
>
> func pString(content string) *string {
>return 
> }

Sure, that's fine.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV8RLnADr1kZaA46aNWtugrfzseT87_heT9_bJupZ_f3g%40mail.gmail.com.


[go-nuts] Assignment of pointer values in a struct...

2020-06-03 Thread Trig
I posted this question the other day and don't see it (may have posted from 
another gmail account and it's still pending approval)... so here I am 
again.

Let's say I have something like below:
type (
   Person struct {
  FirstName *string
   }
)

Usually, I see something like the following when assigning:
fn := "John"
_ = Person{
  FirstName: ,
}

Would something like the following be alright and acceptable practice:
_ = Person{
  FirstName: pString("John")
}


func pString(content string) *string {
   return 
}

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/aa31103a-440b-4375-a1af-383f59c353f2%40googlegroups.com.


Re: [go-nuts] Re: what is the complexity of regexp.MustCompile()?

2020-06-03 Thread 'Axel Wagner' via golang-nuts
Hi,

I can very much recommend reading this list of blog posts by Russ Cox
. They explain the theory behind all of
this. And AIUI, yes, compilation should also be linear. The cost, notably,
is that the regexp package actually can only compile actual regular
expressions which only recognize regular languages, by omitting features
such as back-references. Other regexp-engines are more powerful, at the
expense of no longer being able to have this linear runtime characteristic.
So there is still a tradeoff (though I tend to agree with the one made by
RE2 and thus the regexp-package).


On Wed, Jun 3, 2020 at 11:43 PM Ray Pereda  wrote:

> Typo fix, regexp#MatchString  and
> related Match functions are linear. That is an amazing guarantee and makes
> regular
> expressions 10x more useful than regexps in most other programming
> languages.
>
> Question: Does the *compile* of regular expressions also guaranteed
> linear runtime? I'm considering regular expressions with
> 1000s of keywords; very long regexps. I looked at the source and it was
> not obvious if that is the case. Intricate code.
>
> On Wednesday, June 3, 2020 at 10:07:12 AM UTC-7, Ray Pereda wrote:
>>
>> I believe that the complexity of regexp.MustCompile()
>>  is linear based on this
>> comment in the regexp package overview.
>> 
>>
>> "The regexp implementation provided by this package is guaranteed to run
>> in time linear in the size of the input"
>>
>>
>> What is the complexity of regexp.MustCompile()
>> ? Is it linear in the length
>> of the regular expression?
>>
>> -ray
>>
>>
>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/f51125e7-f66e-45e8-af3a-381f96071d9a%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHP3ymt%2BL63fdw%3Dob8%3Df-FfBtsC%3DGhaO1Q97N3eszvogQ%40mail.gmail.com.


Re: [go-nuts] Re: what is the complexity of regexp.MustCompile()?

2020-06-03 Thread Michael Jones
If you have thousands of fixed strings, a map is your friend. Remarkably
so.

On Wed, Jun 3, 2020 at 2:43 PM Ray Pereda  wrote:

> Typo fix, regexp#MatchString  and
> related Match functions are linear. That is an amazing guarantee and makes
> regular
> expressions 10x more useful than regexps in most other programming
> languages.
>
> Question: Does the *compile* of regular expressions also guaranteed
> linear runtime? I'm considering regular expressions with
> 1000s of keywords; very long regexps. I looked at the source and it was
> not obvious if that is the case. Intricate code.
>
> On Wednesday, June 3, 2020 at 10:07:12 AM UTC-7, Ray Pereda wrote:
>>
>> I believe that the complexity of regexp.MustCompile()
>>  is linear based on this
>> comment in the regexp package overview.
>> 
>>
>> "The regexp implementation provided by this package is guaranteed to run
>> in time linear in the size of the input"
>>
>>
>> What is the complexity of regexp.MustCompile()
>> ? Is it linear in the length
>> of the regular expression?
>>
>> -ray
>>
>>
>>
>> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/f51125e7-f66e-45e8-af3a-381f96071d9a%40googlegroups.com
> 
> .
>
-- 

*Michael T. jonesmichael.jo...@gmail.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQy9TBAJo4Oz_wYsWvacDW_Q_y49bj%3DUCuY1tcdqSR5Ouw%40mail.gmail.com.


[go-nuts] Re: what is the complexity of regexp.MustCompile()?

2020-06-03 Thread Ray Pereda
Typo fix, regexp#MatchString  and 
related Match functions are linear. That is an amazing guarantee and makes 
regular
expressions 10x more useful than regexps in most other programming 
languages.

Question: Does the *compile* of regular expressions also guaranteed linear 
runtime? I'm considering regular expressions with
1000s of keywords; very long regexps. I looked at the source and it was not 
obvious if that is the case. Intricate code. 

On Wednesday, June 3, 2020 at 10:07:12 AM UTC-7, Ray Pereda wrote:
>
> I believe that the complexity of regexp.MustCompile() 
>  is linear based on this 
> comment in the regexp package overview. 
> 
>
> "The regexp implementation provided by this package is guaranteed to run 
> in time linear in the size of the input"
>
>
> What is the complexity of regexp.MustCompile() 
> ? Is it linear in the length 
> of the regular expression?
>
> -ray
>
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f51125e7-f66e-45e8-af3a-381f96071d9a%40googlegroups.com.


[go-nuts] what is the complexity of regexp.MustCompile()?

2020-06-03 Thread Ray Pereda
I believe that the complexity of regexp.MustCompile() 
 is linear based on this 
comment in the regexp package overview. 


"The regexp implementation provided by this package is guaranteed to run in 
time linear in the size of the input"


What is the complexity of regexp.MustCompile() 
? Is it linear in the length of 
the regular expression?

-ray



-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b2067fa0-811e-4b86-bc2b-ce965f1b9cde%40googlegroups.com.


[go-nuts] Multiple freeswitch connections using "github.com/0x19/goesl".!

2020-06-03 Thread David
Hi,

I am using goesl wrapper for connecting to single freeswitch ! But i want 
to connect to multiple freeswitches .! I have used for loop for making 
connection over array of json objects which works fine. But i want to open 
connection to multiple connections in parallel and execute my code on 
multiple freeswitches at the same time ! 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6f1ac643-144b-4684-b3df-044741607df7%40googlegroups.com.


[go-nuts] Re: When "go get" is run in neither a GOPATH directory nor a module-aware directory, should GOPROXY be used or not?

2020-06-03 Thread T L
It looks the default mode in Go 1.14 is still GOPATH mode. So GOPROXY is 
ignored
when "go get" run in neither a GOPATH directory nor a module-aware 
directory.


On Tuesday, June 2, 2020 at 9:12:59 PM UTC-4, T L wrote:

> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b679c366-c5e9-4c0f-afc9-1c7f238ad776%40googlegroups.com.


Re: [go-nuts] Re: go2go (generics) and function binding

2020-06-03 Thread Sebastien Binet
Ian,




‐‐‐ Original Message ‐‐‐
On Monday, June 1, 2020 5:54 AM, Ian Lance Taylor  wrote:

> On Sat, May 30, 2020 at 2:32 AM Sebastien Binet d...@sbinet.org wrote:
>
> > the thing I am trying to solve is, basically, a generic way to:
> >
> > -   pass a function with any number of parameters and a single return value
> > -   "bind" that function to a slice of pointers to values (that will point 
> > to, e.g., values extracted from a db)
> > -   create a closure that returns the value from evaluating the function 
> > with the bound paramaters.
>
> As you've discovered, the current generics design draft does not
> support a variadic list of type parameters.
>
> That's something that might perhaps be added later, if we can figure
> out how to do it. There is some discussion of it starting at
> https://github.com/golang/go/issues/15292#issuecomment-598775120 .

thanks.

Egon came up with some nice improvements upon my first stab at this.
His versions could probably handle the "multiple outputs" possible issue I was 
mentioning in passing.

- version 1
===
package main

type Eval(type T) interface {
Eval() T
}

type Binder interface {
Value(name string) interface{}
}

type Formula(type Result) interface {
Bind(source Binder) error
Eval(Result)
}

type Func2 (type A, B, R) struct {
Call func(A, B) R
A Eval(A)
B Eval(B)
}

func (fn Func2(A, B, R)) Eval() R {
return fn.Call(fn.A.Eval(), fn.B.Eval())
}

func Fn2(type A, B, R)(a, b string, db Binder, eval func(A, B) R) func() R {
fn := Func2(A, B, R){
Call: eval,
A: db.Value(a).(Eval(A)),
B: db.Value(b).(Eval(B)),
}
return fn.Eval
}

type Values map[string]interface{}

func (v Values) Value(name string) interface{} { return v[name]}

type ConstFloat64 float64
func (v ConstFloat64) Eval() float64 { return float64(v) }
type ConstFloat32 float32
func (v ConstFloat32) Eval() float32 { return float32(v) }

func main() {
rows := Values{
"alpha": ConstFloat64(123.123),
"beta": ConstFloat32(53.123),
}

fn := Fn2(float64, float32, int64)(
"alpha", "beta", rows,
func(a float64, b float32) int64 {
return int64(a) + int64(b)
},
)

println("fn=", fn())
}
===

- version 2:
===
package main

type Eval(type T) interface {
Eval() T
}

type Binder interface {
Value(name string) interface{}
}

type Formula(type Result) interface {
Bind(source Binder) error
Eval(Result)
}

type Func2 (type A, B, R) struct {
A, B string
Call func(A, B) R
}

func (fn Func2(A, B, R)) Bind(db Binder) Eval(R) {
a := db.Value(fn.A).(Eval(A))
b := db.Value(fn.B).(Eval(B))
return evalFunc(R)(func() R {
return fn.Call(a.Eval(), b.Eval())
})
}

type evalFunc (type R) func() R
func (fn evalFunc(R)) Eval() R { return fn() }

type Values map[string]interface{}

func (v Values) Value(name string) interface{} { return v[name]}

type ConstFloat64 float64
func (v ConstFloat64) Eval() float64 { return float64(v) }

type ConstFloat32 float32
func (v ConstFloat32) Eval() float32 { return float32(v) }

func main() {
rows := Values{
"alpha": ConstFloat64(123.123),
"beta": ConstFloat32(53.123),
}

form := Func2(float64, float32, int64){
A: "alpha",
B: "beta",
Call: func(a float64, b float32) int64 {
return int64(a) + int64(b)
},
}

fn := form.Bind(rows).Eval

println("fn=", fn())
}
===

-s

PS: here are the direct links:
- 
https://ccbrown.github.io/wasm-go-playground/experimental/generics/#A4Qwxg1iDmCmAEBbEBLAdgKAwFwJ7AQFEA3EAGwAo8D4AVASnnW1gCcAzcBAbwwEgS5Co1oYAvlmoIAQugAmbJmhYcu8XnwBq5AK6wKaEIgQBnbK3TRGzNpzCxuEiTnwIAYgHtWiHWRBVXeAAlWBNfbGtlWzVeeDj4WTQ5ChMPHVZ7BPk2RjZWLwx4+EFKELCyCPFJQLcdNDAAJngAmgBBABoEzqDGM1YdMGx1fgBhcjJ4djqwCg6ExiD+VuLSSlb6fmkVoWkN5yn65vY0eFr6htnO6W76RhLhYOG+VlhsdJPjgDoxskov1s+93onS+0kBq2EeywBzApzQFyk8Dm12C9AoIE6ACN4H1LJ05NjEgpWJ1YKtJtNLvNURT6g8gk9jvAAFwAXlO0wuyJuGj4PzIzPgZPI7X4fFagoJn20ZD06Ponwo93WwLF0klmOlun0mIVSohu1VfAkz1e70maHB5CqLhoMr0JiQIGAAG1cWhoABdGyqeyOaHTZrEeD20KMUMGIymcyWSIqOwOMTqeAvN6sE7EF2GYye5yIkYeNBmNxkDwgbAANgALJNS+XqxgYUH4AWi9gS2XK1W7hDGOw613k6nzf3O9WKMRGBJ84XiwOAMxNUflxeNwMTluz9sLho9oR9ndDs3p2udxcTqcBw7IdAPDT5ADujrZIe1Jl5ACJyMAABYgD+Cq2c5jlWFAAIwNPOnwQfORp8B+mKvP+gFbh2K4XAArFBMFGs4fBMi+bjwhQy5diCO6dMw1ZomKX5kL+/6dAhSEfp0j4mKKfD4ZSICnvWVZYnx2CLnG1ZPFxw4nlRoEgIwADUShdhQupimInEbPwwAWMoZBoBQH7HKyrEWpCVRAA===

- 

Re: [go-nuts] net.go ok function's c != nil check right ?

2020-06-03 Thread apmattil
ooh.. thanks.

On Wednesday, June 3, 2020 at 10:21:24 AM UTC+3, kortschak wrote:
>
> It's perfectly valid to call a method on a nil receiver, so long at the 
> nil receiver is not dereferenced. 
>
> https://play.golang.org/p/Z-zXlj0-eVy 
>
>
> On Wed, 2020-06-03 at 00:03 -0700, apma...@gmail.com  wrote: 
> > Read function at net.go is like this: 
> > 
> > func (c *conn) Read(b []byte) (int, error) { 
> > if !c.ok() { 
> > 
> > the ok checks that c is non nil: 
> > func (c *conn) ok() bool { return c != nil && c.fd != nil } 
> > 
> > how can c ever be nil ? if it would c.ok() call would crash. 
>
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4ff204ac-7eda-4f08-a51e-24a177b95e3e%40googlegroups.com.


Re: [go-nuts] net.go ok function's c != nil check right ?

2020-06-03 Thread 'Dan Kortschak' via golang-nuts
It's perfectly valid to call a method on a nil receiver, so long at the
nil receiver is not dereferenced.

https://play.golang.org/p/Z-zXlj0-eVy


On Wed, 2020-06-03 at 00:03 -0700, apmat...@gmail.com wrote:
> Read function at net.go is like this:
> 
> func (c *conn) Read(b []byte) (int, error) {
> if !c.ok() {
> 
> the ok checks that c is non nil:
> func (c *conn) ok() bool { return c != nil && c.fd != nil }
> 
> how can c ever be nil ? if it would c.ok() call would crash.



-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/8b5522ffb67d8c50863f0c80582935a053be9bd1.camel%40kortschak.io.


[go-nuts] SSL socket listener

2020-06-03 Thread 'Wesley Peng' via golang-nuts
Hello,
How do I program with SSL to make a server listen on specific port which 
accepts SSL transfer only?
Is there any guide for this since I have no experience on SSL socket 
programming.
Thanks.

Wesley Peng
wesleyp...@aol.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/1690752345.1320667.1591168756241%40mail.yahoo.com.


Re: [go-nuts] net.go ok function's c != nil check right ?

2020-06-03 Thread Gregor Best
Methods are part of the type, not of the value. It is perfectly safe to 
call methods on a nil value.


On 03.06.20 09:03, apmat...@gmail.com wrote:

Read function at net.go is like this:

func (c *conn) Read(b []byte) (int, error) {
    if !c.ok() {

the ok checks that c is non nil:
func (c *conn) ok() bool { return c != nil && c.fd != nil }

how can c ever be nil ? if it would c.ok() call would crash.

--
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 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4969df86-c3ec-4b3f-916d-35a986884362%40googlegroups.com 
.


--
--
  Gregor Best
  b...@pferdewetten.de

--
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e0049746-28c2-fb9c-922c-a7a32d86b776%40pferdewetten.de.


[go-nuts] net.go ok function's c != nil check right ?

2020-06-03 Thread apmattil
Read function at net.go is like this:

func (c *conn) Read(b []byte) (int, error) {
if !c.ok() {

the ok checks that c is non nil:
func (c *conn) ok() bool { return c != nil && c.fd != nil }

how can c ever be nil ? if it would c.ok() call would crash.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4969df86-c3ec-4b3f-916d-35a986884362%40googlegroups.com.