[go-nuts] Re: The next layer of abstraction for Go development?

2020-06-14 Thread Saied Seghatoleslami
As evidence for not needing the next layer of abstraction, I offer Django 
class-based-views.  The go approach is much more understandable and easier 
to follow.

On Saturday, June 13, 2020 at 4:11:59 PM UTC-4, Asim Aslam wrote:
>
> Might not be the right place for this discussion but also useful to gauge 
> the experiences of the community. For the most part Go embodies a standard 
> library philosophy and most people are opposed to using any full fledged 
> framework. With Go now being a decade old, I feel as though with that 
> maturity there needs to be maturity in the development ecosystem as well. 
> Every language inevitably has a framework to address the common problems of 
> the platforms they're predominantly used for, whether it was Rails for Ruby 
> or Spring for Java. I've been working on something similar for Go for the 
> past 5 years (https://github.com/micro/go-micro) but have started to 
> shift some of my thinking about how best to approach this for Go.
>
> It's clear that most organisations compose a "shared library" or "starter 
> kit" for building applications or distributed systems so they're not copy 
> and pasting this every time and it gives them one place to change numerous 
> things. This by any other name is a framework but still also a library 
> given you import it. But when these things appear as open source e.g 
> go-micro, there's less inclination for the wider community to adopt. I 
> think over time the standardisation makes sense but maybe in two parts. I 
> think we as a Go community need a standard library for distributed systems 
> development. And it appeared like go-kit might be one of those things but 
> the development there has largely stalled. I'd argue if go-micro could be 
> reoriented into that standard library and the interfaces evolved to meet 
> the needs of developers on top of Go we might have something that 
> accelerates our development and we can all rally around. In doing so we 
> shift our rails/spring like framework efforts to a separate project (
> https://github.com/micro/micro).
>
> All that aside, what is the next layer of abstraction for Go? After a 
> decade we see a lot of tools built with Go, a lot of different development 
> models, but unlike ruby, python, java, etc we are not seeing a dominant 
> framework. Where do we go from here? Where do we end up in the future? Is 
> this something the Go team would look at themselves? Will it come from a 
> cloud provider? Interested to hear the thoughts of everyone here.
>

-- 
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/b8d6397e-ab8d-42d2-aa9f-46608a0d75d6o%40googlegroups.com.


[go-nuts] Re: First column in sql rows.Scan is always zero

2020-06-10 Thread Saied Seghatoleslami
Thank you very much for your help.  Following your suggestions and more 
experimentation, the problem ended up being that I was asserting int, 
string and bool types rather than *int, *string and *bool types.  I should 
have gotten a not ok back, but apparently not.  I will have to figure out 
why.  The other odd thing was that after I fixed the ID field as below, the 
problem moved to the name field.  After that, I ended up changing 
everything as you see below.


func (p *Person) GetBack(get []string, g []interface{}) error {
for i, sp := range get {
switch sp {
case iD:
xID, ok := g[i].(*int)
if !ok {
return fmt.Errorf("ID (int) type assertion failed")
}
p.ID = *xID
case Name:
xName, ok := g[i].(*string)
if !ok {
return fmt.Errorf("Name (string) type assertion failed")
}
p.Name = *xName
case Email:
xEmail, ok := g[i].(*string)
if !ok {
return fmt.Errorf("Email (string) type assertion failed")
}
p.Email = *xEmail
case HashedPassword:
xPass, ok := g[i].(*string)
if !ok {
return fmt.Errorf("Hashed Password (string) type assertion failed")
}
p.HashedPassword = *xPass
case Created:
xCreated, ok := g[i].(*time.Time)
if !ok {
return fmt.Errorf("Created (time.Time) type assertion failed")
}
p.Created = *xCreated
case Role:
xRole, ok := g[i].(*string)
if !ok {
return fmt.Errorf("Role (string) type assertion failed")
}
p.Role = *xRole
case Active:
xActive, ok := g[i].(*bool)
if !ok {
return fmt.Errorf("Active (bool) type assertion failed")
}
p.Active = *xActive
case Online:
xOnline, ok := g[i].(*bool)
if !ok {
return fmt.Errorf("Online (bool) type assertion failed")
}
p.Online = *xOnline
}
}
return nil
}



On Monday, June 8, 2020 at 7:03:14 PM UTC-4, Saied Seghatoleslami wrote:
>
> I am scanning database tables into a structure explicitly (with 
> ) that works just fine (working path below).  
>
> But my tables have different columns, so I am working to generalize the 
> API.  There are two methods that build and reverse a []interface{} to be 
> supplied to scan.  I have listed them in the problem path.  The last item 
> is the people data in the use case.
>
> It scans every column correctly except the first one that is the ID.  
>
> The problem path always returns zero for the ID field while the working 
> path works fine.  I have been staring at it for a day and experimenting 
> with different ideas but no success
>
> Any thoughts?
>
>
>
> //=. Working Path =
>
> //Person is the target for scan.
> type Person struct {
> ID int
> Name   string
> Email  string
> HashedPassword string
> Createdtime.Time
> Role   string
> Active bool
> Online bool
> }
>
> //inside the "get" method to get the data
>
> person := broker.Person{}
> for rows.Next() {
> err := rows.Scan(, , , //g...)
> , , )
> if err != nil {
> if errors.Is(err, sql.ErrNoRows) {
> return broker.ErrNoRecord
> }
> return err
> }
> newPeople = append(newPeople, person)
> //=. Problem Path =
>
> person := broker.Person{}
> g := person.GetItems(e.Get)
> for rows.Next() {
> err := rows.Scan(g...)
> if err != nil {
> if errors.Is(err, sql.ErrNoRows) {
> return broker.ErrNoRecord
> }
> return err
> }
> person.GetBack(e.Get, g)
> newPeople = append(newPeople, person) 
>
>
>
>
> //note that iD, Name, Email... are constants
>
> //GetItems uses the get string to generate an interface to be passed to the
> //sql.Execute statement for the INSERT sql command.
> func (p *Person) GetItems(get []string) []interface{} {
> var g = []interface{}{}
> for _, sp := range get {
> switch sp {
> case iD:
> g = append(g, )
> case Name:
> g = append(g, )
> case Email:
> g = append(g, )
> case HashedPassword:
> g = append(g, )
> case Created:
> g = append(g, )
> case Role:
> g = append(g, )
> case Active:
> g = append(g, )
> case Online:
> g = append(g, )
> }
> }
> return g
> }
>
> //GetBack reverses the get item and takes the interface items and gets the
> //underlying data back.
> func (p *Person) GetBack(get []string, g []interface{}) error {
> var ok bool
> for i, sp := range get {
> switch sp {
> case iD:
> p.ID, ok = g[i].(int)
> if !ok {
> return fmt.Errorf("ID (int) type assertion failed")
> }
> case Name:
> p.Name, ok = g[i].(string)
> if !ok {
> return fmt.Errorf("Name (string) type assertion failed")
> }
> case Email:
> p.Email, ok = g[i].(string)
> if !ok {
> return fmt.Errorf("Email (string) type assertion failed")
> }
> case HashedPassword:

[go-nuts] First column in sql rows.Scan is always zero

2020-06-08 Thread Saied Seghatoleslami
I am scanning database tables into a structure explicitly (with 
) that works just fine (working path below).  

But my tables have different columns, so I am working to generalize the 
API.  There are two methods that build and reverse a []interface{} to be 
supplied to scan.  I have listed them in the problem path.  The last item 
is the people data in the use case.

It scans every column correctly except the first one that is the ID.  

The problem path always returns zero for the ID field while the working 
path works fine.  I have been staring at it for a day and experimenting 
with different ideas but no success

Any thoughts?



//=. Working Path =

//Person is the target for scan.
type Person struct {
ID int
Name   string
Email  string
HashedPassword string
Createdtime.Time
Role   string
Active bool
Online bool
}

//inside the "get" method to get the data

person := broker.Person{}
for rows.Next() {
err := rows.Scan(, , , //g...)
, , )
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return broker.ErrNoRecord
}
return err
}
newPeople = append(newPeople, person)
//=. Problem Path =

person := broker.Person{}
g := person.GetItems(e.Get)
for rows.Next() {
err := rows.Scan(g...)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return broker.ErrNoRecord
}
return err
}
person.GetBack(e.Get, g)
newPeople = append(newPeople, person) 




//note that iD, Name, Email... are constants

//GetItems uses the get string to generate an interface to be passed to the
//sql.Execute statement for the INSERT sql command.
func (p *Person) GetItems(get []string) []interface{} {
var g = []interface{}{}
for _, sp := range get {
switch sp {
case iD:
g = append(g, )
case Name:
g = append(g, )
case Email:
g = append(g, )
case HashedPassword:
g = append(g, )
case Created:
g = append(g, )
case Role:
g = append(g, )
case Active:
g = append(g, )
case Online:
g = append(g, )
}
}
return g
}

//GetBack reverses the get item and takes the interface items and gets the
//underlying data back.
func (p *Person) GetBack(get []string, g []interface{}) error {
var ok bool
for i, sp := range get {
switch sp {
case iD:
p.ID, ok = g[i].(int)
if !ok {
return fmt.Errorf("ID (int) type assertion failed")
}
case Name:
p.Name, ok = g[i].(string)
if !ok {
return fmt.Errorf("Name (string) type assertion failed")
}
case Email:
p.Email, ok = g[i].(string)
if !ok {
return fmt.Errorf("Email (string) type assertion failed")
}
case HashedPassword:
p.HashedPassword, ok = g[i].(string)
if !ok {
return fmt.Errorf("Hashed Password (string) type assertion failed")
}
case Created:
p.Created, ok = g[i].(time.Time)
if !ok {
return fmt.Errorf("Created (time.Time) type assertion failed")
}
case Role:
p.Role, ok = g[i].(string)
if !ok {
return fmt.Errorf("Role (string) type assertion failed")
}
case Active:
p.Active, ok = g[i].(bool)
if !ok {
return fmt.Errorf("Active (bool) type assertion failed")
}
case Online:
p.Online, ok = g[i].(bool)
if !ok {
return fmt.Errorf("Online (bool) type assertion failed")
}
}
}
return nil
}

exchange := Exchange{
Table: table,
Put:   []string{},
Spec:  []string{iD},
Get: []string{iD, Name, Email, HashedPassword, Created,
Active, Online},
People: []Person{
Person{ID: id},
},
Action: "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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5435cf93-5cc0-481d-8a32-13232c9afd60o%40googlegroups.com.


[go-nuts] Re: x, err = some_func(); if err != nil { } seems awkward

2020-06-04 Thread Saied Seghatoleslami
There is also the idea that an error is not necessarily an error in the 
sense that it is wrong but it is something that prevents the operation.  It 
could be that the far end is out of service or the network connection is 
down or the port is closed or the file permissions are set to what is not 
expected (once we missed a big revenue recognition opportunity at the end 
of the quarter because the file permissions were set to something we did 
not expect and we ran out of time during the maintenance window and had to 
back out the upgrade and wait for the next quarter).  In real life, they 
are real situations that must be handled.  Dave Cheney in his blog 
discusses this extensively.  In a way, thinking through the collection of 
events that prevent the happy path from proceeding must be thought through 
first.  

So, it pays to think of what could go wrong and handle it before anything 
else.

On Thursday, June 4, 2020 at 11:44:07 AM UTC-4, lgo...@gmail.com wrote:
>
> ?? Why not a cleaner syntax e.g.  x = some_func ()  #{ }   .. symbol # 
> arbitrarily chosen
>

-- 
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/b961c216-2fdd-45b3-837c-7933e8b89317o%40googlegroups.com.


[go-nuts] Re: Im battling to understand pointers to strings in a function - Please help

2020-05-30 Thread Saied Seghatoleslami
1. Check what is *string[1000].  Maybe you mean *[1000]string
2. Also, it looks like you are passing [1000][2]string etc. to idx, they 
are of different types.  Once you fix that, below are the errors that you 
get
3. Finally, why use fixed size arrays, that is into idiomatic go.  Using 
slices is.

Enter code here/test.go:34:15: cannot use  (type *[1000][2]
string) as type *[1000]string in argument to inx

./test.go:34:28: cannot use  (type *[1000]uint64) as type 
*uint64 in argument to inx

./test.go:38:15: cannot use  (type *[1000][4]string) as type 
*[1000]string in argument to inx

./test.go:38:28: cannot use  (type *[1000]uint64) as type 
*uint64 in argument to inx

./test.go:42:15: cannot use  (type *[1000][8]string) as type 
*[1000]string in argument to inx

./test.go:42:28: cannot use  (type *[1000]uint64) as type 
*uint64 in argument to inx

./test.go:46:15: cannot use  (type *[1000][16]string) as type 
*[1000]string in argument to inx

./test.go:46:29: cannot use  (type *[1000]uint64) as type 
*uint64 in argument to inx

./test.go:50:15: cannot use  (type *[1000][32]string) as type 
*[1000]string in argument to inx

./test.go:50:29: cannot use  (type *[1000]uint64) as type 
*uint64 in argument to inx



On Saturday, May 30, 2020 at 3:43:29 PM UTC-4, Silver 7331 wrote:
>
> I'm 1 day old in this wonderful language and trying my best to learn.
> When I try to build the below code I get the following error/s
>
> ./prog.go:66:6: missing function body
> ./prog.go:66:30: syntax error: unexpected [, expecting comma or )
> ./prog.go:69:2: syntax error: non-declaration statement outside function body
> Go build failed.
>
> I figure it must have something to do with the pointer to the string in the 
> function inx, more specifically sr *string[1000]
>
>
> Thanks in advance.
>
>
> code:
> package main
>
> import "fmt"
>
>
> func main() {
> theStr := 
> "ASDSFHHTBBKLKKJHHDFGHJKHHHJHHKJKJJKJKsdkejffkjf43889934ythbnv3ouy4ti3ykfjjvwkjhfwiuiu4ui4uiyruuhfufuiwefhfwekllfe34t3gphrepgqhg38po3hgvnfh38t98ohgerqoi084rt3ukovpklmnfvb
>  
> [gj po 5hop p6iy 904254uy 45uy 45iuuy 45uy 24u209386 34tu 09y0 5u5ty9025y  
> 59u934tp33tgprg nbnvkoiojh1234567iklr,fcv7ytgvb rgb 
> 98uhbrtghnoikjnrfgvyhntghbuik,rfvokmrtg9iuj5rtfychntf8cihjng vf8ihjngvfi 
> hnb jikjgdfkjverohgvoreihjgolerkgoehvve rlkvoijinvn 
> o4erugoerutjblkgfbkdjfnveorijgve;djvboerijvbofdn"
>  
> var ( 
> iWork int
> sWork string
> iRegister2[1000] uint64
> iRegister4[1000] uint64
> iRegister8[1000] uint64
> iRegister16[1000] uint64
> iRegister32[1000] uint64
> iRegister64[1000] uint64
> sRegister2[1000][2] string
> sRegister4[1000][4] string
> sRegister8[1000][8] string
> sRegister16[1000][16] string
> sRegister32[1000][32] string
> sRegister64[1000][64] string
> iInx2 uint32
> iInx4 uint32
> iInx8 uint32
> iInx16 uint32
> iInx32 uint32
> iInx64 uint32
> )
> iWork = 0
> for iWork = 0; iWork < len(theStr); iWork = iWork + 2{
> if (iWork + 2) < len(theStr){
> sWork = theStr[iWork:iWork + 1]
> inx(sWork, , , )
> }
> if (iWork + 4) % 4 == 0 && (iWork + 4) < len(theStr){
> sWork = theStr[iWork:iWork + 3]
> inx(sWork, , , )
> }
> if ((iWork + 8) % 8) == 0 && (iWork + 8) < len(theStr){
> sWork = theStr[iWork:iWork + 7]
> inx(sWork, , , )
> }
> if ((iWork + 16) % 16) == 0 && (iWork + 16) < len(theStr){
> sWork = theStr[iWork:iWork + 15]
> inx(sWork, , , )
> }
> if ((iWork + 32) % 32) == 0 && (iWork + 32) < len(theStr){
> sWork = theStr[iWork:iWork + 31]
> inx(sWork, , , )
> } 
> if ((iWork + 64) % 64) == 0 && (iWork + 64) < len(theStr){
> sWork = theStr[iWork:iWork + 63]
> inx(sWork, , , )
> } 
> }
> fmt.Printf("2 char array = %d\n", iInx2)
> fmt.Printf("4 char array = %d\n", iInx4)
> fmt.Printf("8 char array = %d\n", iInx8)
> fmt.Printf("16 char array = %d\n", iInx16)
> fmt.Printf("32 char array = %d\n", iInx32)
> fmt.Printf("64 char array = %d\n", iInx64) 
> }
>
> func inx(s string, sr *string[1000], ir *uint64, ii *uint32) {
> var i int
>
> for i = 0; i < *ii && (*sr)[i] != s; i++ {
> }
> if i >= *ii {
> (*sr)[i] = append((*sr)[i],s)
> *ii = i
> (*ir)[i]++
> }
> }
>
>
>

-- 
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/0a9a25b4-1da9-408e-b95f-03bb87f01fba%40googlegroups.com.


[go-nuts] Re: How to parseFile with ...string?

2020-05-20 Thread Saied Seghatoleslami
This is what Alex Edwards in his book "Let's Go" does and I am using it.  
He writes it to a buffer and checks for errors.

Enter code here...

Enter code here...func (app *App) render(w http.ResponseWriter, r *http.
Request, name string) {
t := app.cache[name]
buf := new(bytes.Buffer)
tData, err := app.addDefaultData(app.td, r)
if err != nil {
app.serverError(w, err)
}
err = t.Execute(buf, tData)
if err != nil {
app.serverError(w, err)
return
}
buf.WriteTo(w)
}



On Wednesday, May 20, 2020 at 12:40:38 PM UTC-4, Vivi wrote:
>
> I have not thought of a way how to have 2 or multiple files as a separate 
> string to be parsed by API that request for ...string
> The end goal to verify HTML template for error through a function call, is 
> there a better approach?
>
> func checkHTML(str string) {
> template.ParseFiles(strHTML)
> }
>

-- 
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/11300f3f-1d99-450b-a908-e8c3d523c7fb%40googlegroups.com.


[go-nuts] Re: golang protobuf, struct copy problem

2020-05-20 Thread Saied Seghatoleslami
Why not use gob encoding?  I am using it across nats and it is working 
fine.  The only workaround that I have had to do is to string encode the 
errors and convert them back to errors on the other side.

On Friday, May 8, 2020 at 2:56:22 PM UTC-4, cheng dong wrote:
>
> i use protobuf to do rpc in golang . for every message XXX in proto,  i 
> have to define a struct XXX in go, compute and then copy its field one by 
> one to pb.XXX(because struct XXX have some field not in pb.XXX), when i 
> have many struct XXX, it is very ineffective and very slow.
>
> so how could i use a single struct both used for compute and marshal ?
>

-- 
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/fb03f6e7-3550-4e0c-a92d-8df83bb46e48%40googlegroups.com.


[go-nuts] Re: Variadic Arguments and Interfaces

2020-05-17 Thread Saied Seghatoleslami
I found this article by Nick Gauthier from 2016.  
https://www.meetspaceapp.com/2016/05/23/writing-a-data-mapper-in-go-without-an-orm.html.
  
The original idea is contributed to Martin Fowler.

Someone else has solved this problem before.  

On Friday, September 7, 2012 at 4:45:07 PM UTC-4, Paddy Foran wrote:
>
> Consider the following: 
>
> In package fmt: func Println(a …interface{})
>
> One would think the following code would work:
>
> func main() {
> testslice := []string { "this", "is", "a", "test" }
> fmt.Println(testslice…)
> }
>
> One would subsequently be met with "cannot use testslice (type []string) 
> as type []interface {} in function argument" (
> http://play.golang.org/p/H3349TDJnS)
>
> On the other hand, if one were to try:
>
> func print(words …string) {
> for _, word := range words {
> fmt.Printf("%s", word)
> }
> }
>
> func main() {
> testslice := []string { "this", "is", "a", "test" }
> print(testslice…)
> }
>
> Everything works as expected (http://play.golang.org/p/1ZnIwge19V). Can 
> anyone explain why the empty interface in variadic parameters prevents me 
> from using argument expansion?
>
> God, I hope I used the right names for all these things.
>

-- 
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/47536abf-c826-4b11-ad21-6435cc5d9ad7%40googlegroups.com.


Re: [go-nuts] Re: Variadic Arguments and Interfaces

2020-05-17 Thread Saied Seghatoleslami
I have it working well by listing the individual conditions.  But I have a 
bunch of functions that do similar things (authenticate a user based on 
their email and password, get a list of users based on role and active 
status, get an individual user based on ID, etc.) and I was looking to 
combine them into a more generalized function.  So far I have not found a 
way.

On Sunday, May 17, 2020 at 6:39:07 PM UTC-4, Steven Hartland wrote:
>
> Did you use the correct calling convension e.g.
> db.Query(query, cond...)
>
> The ... makes the slice variadic, passing echData.Active, exchData.Role 
> instead of just a interface slice
>
> On 17/05/2020 23:27, Saied Seghatoleslami wrote:
>
> I hate to dig up something from 2012, but I have come across a similar 
> issue where I can use an explanation.  The signature of the Query function 
> in the sql package is: 
>
> func (db *DB <https://golang.org/pkg/database/sql/#DB>) Query(query string 
> <https://golang.org/pkg/builtin/#string>, args ...interface{}) (*Rows 
> <https://golang.org/pkg/database/sql/#Rows>, error 
> <https://golang.org/pkg/builtin/#error>)
>
>
> so, one would assume that passing something like this  for args would work 
> (Active is bool and Role is a string:
>
> var cond = []interface{}{exchData.Active, exchData.Role}
>
> but it does not, it results in this error:
>
> sql: converting argument $1 type: unsupported type []interface {}, a 
> slice of interface
>
> I suspect there is a good explanation for this that I do not get.
>
>
>
> On Friday, September 7, 2012 at 4:45:07 PM UTC-4, Paddy Foran wrote: 
>>
>> Consider the following: 
>>
>> In package fmt: func Println(a …interface{})
>>
>> One would think the following code would work:
>>
>> func main() {
>> testslice := []string { "this", "is", "a", "test" }
>> fmt.Println(testslice…)
>> }
>>
>> One would subsequently be met with "cannot use testslice (type []string) 
>> as type []interface {} in function argument" (
>> http://play.golang.org/p/H3349TDJnS)
>>
>> On the other hand, if one were to try:
>>
>> func print(words …string) {
>> for _, word := range words {
>> fmt.Printf("%s", word)
>> }
>> }
>>
>> func main() {
>> testslice := []string { "this", "is", "a", "test" }
>> print(testslice…)
>> }
>>
>> Everything works as expected (http://play.golang.org/p/1ZnIwge19V). Can 
>> anyone explain why the empty interface in variadic parameters prevents me 
>> from using argument expansion?
>>
>> God, I hope I used the right names for all these things.
>>
> -- 
> 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 golan...@googlegroups.com .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>
>

-- 
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/262da5fc-ccbb-43f3-838f-2d4f04a43200%40googlegroups.com.


[go-nuts] Re: Variadic Arguments and Interfaces

2020-05-17 Thread Saied Seghatoleslami
I hate to dig up something from 2012, but I have come across a similar 
issue where I can use an explanation.  The signature of the Query function 
in the sql package is:

func (db *DB ) Query(query string 
, args ...interface{}) (*Rows 
, error 
)


so, one would assume that passing something like this  for args would work 
(Active is bool and Role is a string:

var cond = []interface{}{exchData.Active, exchData.Role}

but it does not, it results in this error:

sql: converting argument $1 type: unsupported type []interface {}, a slice 
of interface

I suspect there is a good explanation for this that I do not get.



On Friday, September 7, 2012 at 4:45:07 PM UTC-4, Paddy Foran wrote:
>
> Consider the following: 
>
> In package fmt: func Println(a …interface{})
>
> One would think the following code would work:
>
> func main() {
> testslice := []string { "this", "is", "a", "test" }
> fmt.Println(testslice…)
> }
>
> One would subsequently be met with "cannot use testslice (type []string) 
> as type []interface {} in function argument" (
> http://play.golang.org/p/H3349TDJnS)
>
> On the other hand, if one were to try:
>
> func print(words …string) {
> for _, word := range words {
> fmt.Printf("%s", word)
> }
> }
>
> func main() {
> testslice := []string { "this", "is", "a", "test" }
> print(testslice…)
> }
>
> Everything works as expected (http://play.golang.org/p/1ZnIwge19V). Can 
> anyone explain why the empty interface in variadic parameters prevents me 
> from using argument expansion?
>
> God, I hope I used the right names for all these things.
>

-- 
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/1cc28db0-98c6-49cd-bd3e-7752ef2b5328%40googlegroups.com.


[go-nuts] Re: Unmarshal XML element to interface{}

2020-05-14 Thread Saied Seghatoleslami
I have tried unmarshalling various JSON and XML files with limited 
success.  So I ended up writing a "lexer" along the lines of Rob Pike's 
lecture in Australia.  I have had good success with it in a bunch of 
projects.  I would be very interested to get some comments on what the 
community thinks of decoding XML, JSON and similarly encoded objects in 
this way.  https://github.com/Saied74/lexer2

On Thursday, August 20, 2015 at 12:52:45 PM UTC-4, hajd...@gmail.com wrote:
>
> Is there any reason this *shouldn't* work? ( I realize it doesn't, just 
> curious since you can marshal an empty interface ).
>
> A contrived example: ( https://play.golang.org/p/s-Lh0qDwAP)
>
> type Person struct {
> XMLName   xml.Name`xml:"person"`
> FirstName string  `xml:"firstname"`
> Parents interface{} `xml:"parent"`
> }
>
> func main() {
> type Parent struct {
> FirstName string `xml:"name"`
> LastName string `xml:"lastname"`
> }
> p := {FirstName: "Steve"}
> p.Parents = []Parent{Parent{"Jack","Doe"}, Parent{"Lynne","Doe"}}
> data, err := xml.Marshal(p)
> if err != nil {
> fmt.Println(err)
> }
> fmt.Println("Marshalled:",string(data))
> p2 := {}
> p2.Parents = []Parent{}
> err = xml.Unmarshal(data, p2)
> if err != nil {
> fmt.Println(err)
> }
> fmt.Println("Unmarshalled:", p2)
> }
>
>
> I get that by being an empty interface{}, there are no fields that are 
> exported for it to look at.  Except that I'm assigning a concrete type to 
> the interface{}, so shouldn't Unmarshal be able to reflect that interface{} 
> and find the struct/tag names to Unmarshal the data?  I'm assuming ( and 
> guessing I'm wrong ) that that's how Marshal does it?  I think I'd probably 
> be less confused if Marshal wasn't working as well, but I don't get why 
> Marshal can deal with a interface{} and Unmarshal can't.
>
> The real use case I have being that the XML response I'm getting has some 
> static elements and then it has dynamic elements:
>
> 
>   data
>   data
>   
> data
> data
>   
>   
> ..
>   
> 
>
> I have the static fields in a struct, but fieldname's returned in the 
> record elements change, depending on which database table is being returned 
> by the api.  I want to be able to create a record struct that matches what 
> I know the record will look like for each call, and then compose the whole 
> struct ( static fields + the dynamic fields ) that I'm unmarshalling into.
>
> The solution I have right now is to have a byte array that captures the 
> innerxml and then unmarshal that separately, but I felt like this would be 
> a cleaner solution.  ( https://play.golang.org/p/z3BS6tjqgW )
>
> If there isn't anyway to do this - is there anyway to grab a whole 
>  record, with the  tags included?  My byte 
> solution works, but the issue I run into is that my innerxml field just 
> ends up with , with no 
> surrounding  tags.  So I have to add the parent tags back so that I 
> can unmarshal to a Parent struct, as you can see in the example.
>
> Any help appreciated!
>
> Steve
>

-- 
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/f4001087-f7b2-47db-aa62-00cf3a13ecd2%40googlegroups.com.


[go-nuts] Re: suspect or: role != admin || role != superadmin

2020-05-11 Thread Saied Seghatoleslami
Thank you, guys.  I walked myself into a logical trap.  Professor Isapovich 
is probably turning in his grave and giving me an F in some heavenly grade 
book.

On Monday, May 11, 2020 at 2:53:02 PM UTC-4, Saied Seghatoleslami wrote:
>
> I have seen a ticket on this topic (or something related to it) on Github 
> but I thought I would ask this community first:
>
> In first instance, I got "suspect or: role != admin || role != superadmin"
> In the second instance, it works just fine.  I have verified that role is 
> string type (with %T verb).
>
> since role can be admin, superadmin, or anything else for that matter, why 
> would the first case generate the suspect message, and the second case 
> works fine.
>
> I am running go version go1.13.4 darwin/amd64 on a Mac
>
>
> First Instance:
>
> const (
>  admin  = "admin"
>  superadmin = "superadmin"
> )
>
> invalidRole := role != admin || role != superadmin
>
>
>
> Second instance:
>
> const (
>  admin  = "admin"
>  superadmin = "superadmin"
> )
>
> validRole := role == admin || role == superadmin
>
>
>
>

-- 
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/b30582cf-01f2-4281-a11d-a6d2ed26dc6a%40googlegroups.com.


[go-nuts] suspect or: role != admin || role != superadmin

2020-05-11 Thread Saied Seghatoleslami
I have seen a ticket on this topic (or something related to it) on Github 
but I thought I would ask this community first:

In first instance, I got "suspect or: role != admin || role != superadmin"
In the second instance, it works just fine.  I have verified that role is 
string type (with %T verb).

since role can be admin, superadmin, or anything else for that matter, why 
would the first case generate the suspect message, and the second case 
works fine.

I am running go version go1.13.4 darwin/amd64 on a Mac


First Instance:

const (
 admin  = "admin"
 superadmin = "superadmin"
)

invalidRole := role != admin || role != superadmin



Second instance:

const (
 admin  = "admin"
 superadmin = "superadmin"
)

validRole := role == admin || role == superadmin



-- 
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/ef2e9e72-0f14-49d9-99fd-950bab0b5a41%40googlegroups.com.


[go-nuts] Re: Why I fear Go

2020-05-09 Thread Saied Seghatoleslami
You should go for it.  If you think you can, or you think you can't, in 
both cases you are right.

On Saturday, May 9, 2020 at 1:57:23 PM UTC-4, shammah Zealsham Agwor wrote:
>
> I have been programming since 2016 but I have never really dived deep into 
> any language and haven't got a job with any . I decided to change all that 
> and focus with every soul in me on golang. But I have my fear as every go 
> job I have seen are looking for senior developers. And from what I noticed 
> in big corps and small ones alike ,people writing go there are senior who 
> wants to port existing large scale system to go . I'm afraid I'll never be 
> able to get an entry job with it and all my hard work will be a waste and 
> I'll have to put in such efforts again into another language . Should I 
> still go for it . I've been learning it for months now and I'm scared .

-- 
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/1cd7a168-e06b-4828-9333-807d834b3bc2%40googlegroups.com.


Re: [go-nuts] A modest format suggestion

2020-04-24 Thread Saied Seghatoleslami
Doesn't this style of writing assume that there are a lot of arguments to
be passed to function which I think is not a good practice since it makes
it much harder to remember what the function does and how to call and most
importantly, how to debug it when becomes necessary?

So, if there are a lot of arguments to be passed to the function, it is
best to redesign it and use a data structure that encapsulates the
arguments.  Otherwise, what is wrong with this?


// Great is a really great function anArg does this and anotherArg does
that.
func Great(anArg int, anotherArg string) (err error) {
return nil
}

On Fri, Apr 24, 2020 at 3:32 PM Scott Deerwester 
wrote:

> I greatly appreciate the fact that Go has a coding standard. I have a
> modest proposed modification. Instead of this:
>
> // Great is a really great function.
> func Great(
> anArg int, // This explains anArg
> anotherArg string, // This explains anotherArg
> ) (err error) {
> ...
>
> I'd think that this:
>
> // Great is a really great function.
> func Great(
> anArg  int,// This explains anArg
> anotherArg string, // This explains anotherArg
> ) (err error) {
> ...
>
>
> would be both clearer and more consistent with this:
>
> var (
> aVar   = 12  // This explains aVar
> anotherVar = "something" // This explains anotherVar
> )
>
>
> or this:
>
> type SomeStruct struct {
> FieldName string
> Value int
> }
>
>
> var aStructList = []*SomeStruct {
> {
> FieldName: "SomeName", // Comment for FieldName
> Value: 12, // Comment for Value
> },
> }
>
> which are already part of the standard coding style. Is this the right
> place to make such a proposal?
>
> --
> 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/8a4fa305-a8bc-4512-8f23-6a42b479dd2d%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/CAOdwK1k%3DFf82EG91njLq37ybvQZA_Hq0KmPBG%2B1FW_CYF3h1Xg%40mail.gmail.com.