Skip to content

Commit e25c2c3

Browse files
committed
changed field names in hardware proto to use snake case (convention)
1 parent e8bddce commit e25c2c3

File tree

8 files changed

+207
-204
lines changed

8 files changed

+207
-204
lines changed

cli/tink/cmd/hardware/id.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var idCmd = &cobra.Command{
2323
},
2424
Run: func(cmd *cobra.Command, args []string) {
2525
for _, id := range args {
26-
hw, err := client.HardwareClient.ByID(context.Background(), &hardware.GetRequest{ID: id})
26+
hw, err := client.HardwareClient.ByID(context.Background(), &hardware.GetRequest{Id: id})
2727
if err != nil {
2828
log.Fatal(err)
2929
}

cli/tink/cmd/hardware/ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var ipCmd = &cobra.Command{
2929
},
3030
Run: func(cmd *cobra.Command, args []string) {
3131
for _, ip := range args {
32-
hw, err := client.HardwareClient.ByIP(context.Background(), &hardware.GetRequest{IP: ip})
32+
hw, err := client.HardwareClient.ByIP(context.Background(), &hardware.GetRequest{Ip: ip})
3333
if err != nil {
3434
log.Fatal(err)
3535
}

cli/tink/cmd/hardware/mac.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var macCmd = &cobra.Command{
2929
},
3030
Run: func(cmd *cobra.Command, args []string) {
3131
for _, mac := range args {
32-
hw, err := client.HardwareClient.ByMAC(context.Background(), &hardware.GetRequest{MAC: mac})
32+
hw, err := client.HardwareClient.ByMAC(context.Background(), &hardware.GetRequest{Mac: mac})
3333
if err != nil {
3434
log.Fatal(err)
3535
}

cli/tink/cmd/hardware/watch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var watchCmd = &cobra.Command{
2727
stdoutLock := sync.Mutex{}
2828
for _, id := range args {
2929
go func(id string) {
30-
stream, err := client.HardwareClient.Watch(context.Background(), &hardware.GetRequest{ID: id})
30+
stream, err := client.HardwareClient.Watch(context.Background(), &hardware.GetRequest{Id: id})
3131
if err != nil {
3232
log.Fatal(err)
3333
}

db/hardware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func GetByID(ctx context.Context, db *sql.DB, id string) (string, error) {
141141
}
142142

143143
// GetAll : get data for all machine
144-
func GetAll(db *sql.DB, fn func(string) error) error {
144+
func GetAll(db *sql.DB, fn func([]byte) error) error {
145145
rows, err := db.Query(`
146146
SELECT data
147147
FROM hardware
@@ -163,7 +163,7 @@ func GetAll(db *sql.DB, fn func(string) error) error {
163163
return err
164164
}
165165

166-
err = fn(string(buf))
166+
err = fn(buf)
167167
if err != nil {
168168
return err
169169
}

grpc-server/hardware.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ func (s *server) by(method string, fn func() (string, error)) (*hardware.Hardwar
132132

133133
func (s *server) ByMAC(ctx context.Context, in *hardware.GetRequest) (*hardware.Hardware, error) {
134134
return s.by("ByMAC", func() (string, error) {
135-
return db.GetByMAC(ctx, s.db, in.MAC)
135+
return db.GetByMAC(ctx, s.db, in.Mac)
136136
})
137137
}
138138

139139
func (s *server) ByIP(ctx context.Context, in *hardware.GetRequest) (*hardware.Hardware, error) {
140140
return s.by("ByIP", func() (string, error) {
141-
return db.GetByIP(ctx, s.db, in.IP)
141+
return db.GetByIP(ctx, s.db, in.Ip)
142142
})
143143
}
144144

145145
// ByID implements hardware.ByID
146146
func (s *server) ByID(ctx context.Context, in *hardware.GetRequest) (*hardware.Hardware, error) {
147147
return s.by("ByID", func() (string, error) {
148-
return db.GetByID(ctx, s.db, in.ID)
148+
return db.GetByID(ctx, s.db, in.Id)
149149
})
150150
}
151151

@@ -167,9 +167,9 @@ func (s *server) All(_ *hardware.Empty, stream hardware.HardwareService_AllServe
167167

168168
timer := prometheus.NewTimer(metrics.CacheDuration.With(labels))
169169
defer timer.ObserveDuration()
170-
err := db.GetAll(s.db, func(j string) error {
170+
err := db.GetAll(s.db, func(j []byte) error {
171171
hw := &hardware.Hardware{}
172-
json.Unmarshal([]byte(j), hw)
172+
json.Unmarshal(j, hw)
173173
return stream.Send(hw)
174174
})
175175
if err != nil {
@@ -182,16 +182,16 @@ func (s *server) All(_ *hardware.Empty, stream hardware.HardwareService_AllServe
182182
}
183183

184184
func (s *server) Watch(in *hardware.GetRequest, stream hardware.HardwareService_WatchServer) error {
185-
l := logger.With("id", in.ID)
185+
l := logger.With("id", in.Id)
186186

187187
ch := make(chan string, 1)
188188
s.watchLock.Lock()
189-
old, ok := s.watch[in.ID]
189+
old, ok := s.watch[in.Id]
190190
if ok {
191191
l.Info("evicting old watch")
192192
close(old)
193193
}
194-
s.watch[in.ID] = ch
194+
s.watch[in.Id] = ch
195195
s.watchLock.Unlock()
196196

197197
labels := prometheus.Labels{"method": "Watch", "op": "push"}
@@ -204,7 +204,7 @@ func (s *server) Watch(in *hardware.GetRequest, stream hardware.HardwareService_
204204
return
205205
}
206206
s.watchLock.Lock()
207-
delete(s.watch, in.ID)
207+
delete(s.watch, in.Id)
208208
s.watchLock.Unlock()
209209
close(ch)
210210
}()

0 commit comments

Comments
 (0)