forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hostinfo: fix using default conn and overriding values (apache#1009)
Only set values in HostInfo.update if they were not set previously. Fix using default port when we have a port available from an event frame. Fix overwriting the supplied ports in a hostinfo
- Loading branch information
Showing
3 changed files
with
108 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build genhostinfo | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"sync" | ||
|
||
"github.com/gocql/gocql" | ||
) | ||
|
||
func gen(clause, field string) { | ||
fmt.Printf("if h.%s == %s {\n", field, clause) | ||
fmt.Printf("\th.%s = from.%s\n", field, field) | ||
fmt.Println("}") | ||
} | ||
|
||
func main() { | ||
t := reflect.ValueOf(&gocql.HostInfo{}).Elem().Type() | ||
mu := reflect.TypeOf(sync.RWMutex{}) | ||
|
||
for i := 0; i < t.NumField(); i++ { | ||
f := t.Field(i) | ||
if f.Type == mu { | ||
continue | ||
} | ||
|
||
switch f.Type.Kind() { | ||
case reflect.Slice: | ||
gen("nil", f.Name) | ||
case reflect.String: | ||
gen(`""`, f.Name) | ||
case reflect.Int: | ||
gen("0", f.Name) | ||
case reflect.Struct: | ||
gen("("+f.Type.Name()+"{})", f.Name) | ||
case reflect.Bool, reflect.Int32: | ||
continue | ||
default: | ||
panic(fmt.Sprintf("unknown field: %s", f)) | ||
} | ||
} | ||
|
||
} |