Skip to content

Commit 7324542

Browse files
Merge pull request #18 from Cepat-Kilat-Teknologi/develop
Sort and Lint
2 parents 52437ad + e2e2031 commit 7324542

File tree

23 files changed

+170
-42
lines changed

23 files changed

+170
-42
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-alpine AS dev
1+
FROM golang:1.25-alpine AS dev
22
RUN go install github.com/air-verse/air@latest
33
WORKDIR /app
44
COPY . /app/

app/app.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package app
22

33
import (
44
"context"
5+
"net/http"
6+
"os"
7+
58
"github.com/megadata-dev/go-snmp-olt-zte-c320/config"
69
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/handler"
710
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/repository"
@@ -12,18 +15,30 @@ import (
1215
"github.com/megadata-dev/go-snmp-olt-zte-c320/pkg/snmp"
1316
rds "github.com/redis/go-redis/v9"
1417
"github.com/rs/zerolog/log"
15-
"net/http"
16-
"os"
1718
)
1819

20+
// App represents the main application structure that holds the HTTP router
21+
// and manages the application lifecycle including dependencies initialization
22+
// and server startup.
1923
type App struct {
2024
router http.Handler
2125
}
2226

27+
// New creates and returns a new instance of the App with initialized dependencies.
28+
// It prepares the application for startup but does not start the server.
2329
func New() *App {
2430
return &App{}
2531
}
2632

33+
// Start initializes the application components, sets up connections to external services
34+
// (Redis and SNMP), and starts the HTTP server. It handles graceful shutdown on context
35+
// cancellation and ensures proper cleanup of resources.
36+
//
37+
// Parameters:
38+
// - ctx: context.Context for cancellation and timeout propagation
39+
//
40+
// Returns:
41+
// - error: returns any error that occurs during application startup or shutdown
2742
func (a *App) Start(ctx context.Context) error {
2843

2944
// Get config path from APP_ENV environment variable

app/routes.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package app
22

33
import (
4+
"net/http"
5+
"os"
6+
47
"github.com/go-chi/chi/v5"
58
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/handler"
69
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/middleware"
710
"github.com/rs/zerolog"
811
"github.com/rs/zerolog/log"
9-
"net/http"
10-
"os"
1112
)
1213

1314
func loadRoutes(onuHandler *handler.OnuHandler) http.Handler {

cmd/api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
56
"github.com/megadata-dev/go-snmp-olt-zte-c320/app"
67
"github.com/rs/zerolog/log"
78
)

config/config.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/spf13/viper"
77
)
88

9+
// Config represents the main application configuration structure
10+
// that contains all sub-configurations for SNMP, Redis, OLT, and individual PON boards.
911
type Config struct {
1012
SnmpCfg SnmpConfig
1113
RedisCfg RedisConfig
@@ -44,12 +46,16 @@ type Config struct {
4446
Board2Pon16 Board2Pon16
4547
}
4648

49+
// SnmpConfig contains configuration parameters for SNMP connection
50+
// including target IP address, port, and community string.
4751
type SnmpConfig struct {
48-
Ip string `mapstructure:"ip"`
52+
IP string `mapstructure:"ip"` // Target IP address of the SNMP device
4953
Port uint16 `mapstructure:"port"`
5054
Community string `mapstructure:"community"`
5155
}
5256

57+
// RedisConfig contains configuration parameters for Redis connection
58+
// including host, port, authentication, and connection pooling settings.
5359
type RedisConfig struct {
5460
Host string `mapstructure:"host"`
5561
Port string `mapstructure:"port"`
@@ -61,13 +67,17 @@ type RedisConfig struct {
6167
PoolTimeout int `mapstructure:"pool_timeout"`
6268
}
6369

70+
// OltConfig contains base OID configurations for OLT device management
71+
// including common OIDs for ONU identification and type mapping.
6472
type OltConfig struct {
6573
BaseOID1 string `mapstructure:"base_oid_1"`
6674
BaseOID2 string `mapstructure:"base_oid_2"`
6775
OnuIDNameAllPon string `mapstructure:"onu_id_name"`
6876
OnuTypeAllPon string `mapstructure:"onu_type"`
6977
}
7078

79+
// Board1Pon1 contains OID configurations for Board 1 Port 1 ONU management
80+
// including identifiers, status, power levels, and diagnostic information.
7181
type Board1Pon1 struct {
7282
OnuIDNameOID string `mapstructure:"onu_id_name"`
7383
OnuTypeOID string `mapstructure:"onu_type"`
@@ -83,6 +93,7 @@ type Board1Pon1 struct {
8393
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
8494
}
8595

96+
// Board1Pon2 contains OID configurations for Board 1 Port 2 ONU management.
8697
type Board1Pon2 struct {
8798
OnuIDNameOID string `mapstructure:"onu_id_name"`
8899
OnuTypeOID string `mapstructure:"onu_type"`
@@ -98,6 +109,7 @@ type Board1Pon2 struct {
98109
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
99110
}
100111

112+
// Board1Pon3 contains OID configurations for Board 1 Port 3 ONU management.
101113
type Board1Pon3 struct {
102114
OnuIDNameOID string `mapstructure:"onu_id_name"`
103115
OnuTypeOID string `mapstructure:"onu_type"`
@@ -113,6 +125,7 @@ type Board1Pon3 struct {
113125
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
114126
}
115127

128+
// Board1Pon4 contains OID configurations for Board 1 Port 4 ONU management.
116129
type Board1Pon4 struct {
117130
OnuIDNameOID string `mapstructure:"onu_id_name"`
118131
OnuTypeOID string `mapstructure:"onu_type"`
@@ -128,6 +141,7 @@ type Board1Pon4 struct {
128141
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
129142
}
130143

144+
// Board1Pon5 contains OID configurations for Board 1 Port 5 ONU management.
131145
type Board1Pon5 struct {
132146
OnuIDNameOID string `mapstructure:"onu_id_name"`
133147
OnuTypeOID string `mapstructure:"onu_type"`
@@ -143,6 +157,7 @@ type Board1Pon5 struct {
143157
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
144158
}
145159

160+
// Board1Pon6 contains OID configurations for Board 1 Port 6 ONU management.
146161
type Board1Pon6 struct {
147162
OnuIDNameOID string `mapstructure:"onu_id_name"`
148163
OnuTypeOID string `mapstructure:"onu_type"`
@@ -158,6 +173,7 @@ type Board1Pon6 struct {
158173
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
159174
}
160175

176+
// Board1Pon7 contains OID configurations for Board 1 Port 7 ONU management.
161177
type Board1Pon7 struct {
162178
OnuIDNameOID string `mapstructure:"onu_id_name"`
163179
OnuTypeOID string `mapstructure:"onu_type"`
@@ -173,6 +189,7 @@ type Board1Pon7 struct {
173189
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
174190
}
175191

192+
// Board1Pon8 contains OID configurations for Board 1 Port 8 ONU management.
176193
type Board1Pon8 struct {
177194
OnuIDNameOID string `mapstructure:"onu_id_name"`
178195
OnuTypeOID string `mapstructure:"onu_type"`
@@ -188,6 +205,7 @@ type Board1Pon8 struct {
188205
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
189206
}
190207

208+
// Board1Pon9 contains OID configurations for Board 1 Port 9 ONU management.
191209
type Board1Pon9 struct {
192210
OnuIDNameOID string `mapstructure:"onu_id_name"`
193211
OnuTypeOID string `mapstructure:"onu_type"`
@@ -203,6 +221,7 @@ type Board1Pon9 struct {
203221
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
204222
}
205223

224+
// Board1Pon10 contains OID configurations for Board 1 Port 10 ONU management.
206225
type Board1Pon10 struct {
207226
OnuIDNameOID string `mapstructure:"onu_id_name"`
208227
OnuTypeOID string `mapstructure:"onu_type"`
@@ -218,6 +237,7 @@ type Board1Pon10 struct {
218237
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
219238
}
220239

240+
// Board1Pon11 contains OID configurations for Board 1 Port 11 ONU management.
221241
type Board1Pon11 struct {
222242
OnuIDNameOID string `mapstructure:"onu_id_name"`
223243
OnuTypeOID string `mapstructure:"onu_type"`
@@ -233,6 +253,7 @@ type Board1Pon11 struct {
233253
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
234254
}
235255

256+
// Board1Pon12 contains OID configurations for Board 1 Port 12 ONU management.
236257
type Board1Pon12 struct {
237258
OnuIDNameOID string `mapstructure:"onu_id_name"`
238259
OnuTypeOID string `mapstructure:"onu_type"`
@@ -248,6 +269,7 @@ type Board1Pon12 struct {
248269
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
249270
}
250271

272+
// Board1Pon13 contains OID configurations for Board 1 Port 13 ONU management.
251273
type Board1Pon13 struct {
252274
OnuIDNameOID string `mapstructure:"onu_id_name"`
253275
OnuTypeOID string `mapstructure:"onu_type"`
@@ -263,6 +285,7 @@ type Board1Pon13 struct {
263285
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
264286
}
265287

288+
// Board1Pon14 contains OID configurations for Board 1 Port 14 ONU management.
266289
type Board1Pon14 struct {
267290
OnuIDNameOID string `mapstructure:"onu_id_name"`
268291
OnuTypeOID string `mapstructure:"onu_type"`
@@ -278,6 +301,7 @@ type Board1Pon14 struct {
278301
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
279302
}
280303

304+
// Board1Pon15 contains OID configurations for Board 1 Port 15 ONU management.
281305
type Board1Pon15 struct {
282306
OnuIDNameOID string `mapstructure:"onu_id_name"`
283307
OnuTypeOID string `mapstructure:"onu_type"`
@@ -293,6 +317,7 @@ type Board1Pon15 struct {
293317
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
294318
}
295319

320+
// Board1Pon16 contains OID configurations for Board 1 Port 16 ONU management.
296321
type Board1Pon16 struct {
297322
OnuIDNameOID string `mapstructure:"onu_id_name"`
298323
OnuTypeOID string `mapstructure:"onu_type"`
@@ -307,6 +332,8 @@ type Board1Pon16 struct {
307332
OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
308333
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
309334
}
335+
336+
// Board2Pon1 contains OID configurations for Board 2 Port 1 ONU management.
310337
type Board2Pon1 struct {
311338
OnuIDNameOID string `mapstructure:"onu_id_name"`
312339
OnuTypeOID string `mapstructure:"onu_type"`
@@ -322,6 +349,7 @@ type Board2Pon1 struct {
322349
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
323350
}
324351

352+
// Board2Pon2 contains OID configurations for Board 2 Port 2 ONU management.
325353
type Board2Pon2 struct {
326354
OnuIDNameOID string `mapstructure:"onu_id_name"`
327355
OnuTypeOID string `mapstructure:"onu_type"`
@@ -337,6 +365,7 @@ type Board2Pon2 struct {
337365
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
338366
}
339367

368+
// Board2Pon3 contains OID configurations for Board 2 Port 3 ONU management.
340369
type Board2Pon3 struct {
341370
OnuIDNameOID string `mapstructure:"onu_id_name"`
342371
OnuTypeOID string `mapstructure:"onu_type"`
@@ -352,6 +381,7 @@ type Board2Pon3 struct {
352381
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
353382
}
354383

384+
// Board2Pon4 contains OID configurations for Board 2 Port 4 ONU management.
355385
type Board2Pon4 struct {
356386
OnuIDNameOID string `mapstructure:"onu_id_name"`
357387
OnuTypeOID string `mapstructure:"onu_type"`
@@ -367,6 +397,7 @@ type Board2Pon4 struct {
367397
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
368398
}
369399

400+
// Board2Pon5 contains OID configurations for Board 2 Port 5 ONU management.
370401
type Board2Pon5 struct {
371402
OnuIDNameOID string `mapstructure:"onu_id_name"`
372403
OnuTypeOID string `mapstructure:"onu_type"`
@@ -382,6 +413,7 @@ type Board2Pon5 struct {
382413
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
383414
}
384415

416+
// Board2Pon6 contains OID configurations for Board 2 Port 6 ONU management.
385417
type Board2Pon6 struct {
386418
OnuIDNameOID string `mapstructure:"onu_id_name"`
387419
OnuTypeOID string `mapstructure:"onu_type"`
@@ -397,6 +429,7 @@ type Board2Pon6 struct {
397429
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
398430
}
399431

432+
// Board2Pon7 contains OID configurations for Board 2 Port 7 ONU management.
400433
type Board2Pon7 struct {
401434
OnuIDNameOID string `mapstructure:"onu_id_name"`
402435
OnuTypeOID string `mapstructure:"onu_type"`
@@ -412,6 +445,7 @@ type Board2Pon7 struct {
412445
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
413446
}
414447

448+
// Board2Pon8 contains OID configurations for Board 2 Port 8 ONU management.
415449
type Board2Pon8 struct {
416450
OnuIDNameOID string `mapstructure:"onu_id_name"`
417451
OnuTypeOID string `mapstructure:"onu_type"`
@@ -427,6 +461,7 @@ type Board2Pon8 struct {
427461
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
428462
}
429463

464+
// Board2Pon9 contains OID configurations for Board 2 Port 9 ONU management.
430465
type Board2Pon9 struct {
431466
OnuIDNameOID string `mapstructure:"onu_id_name"`
432467
OnuTypeOID string `mapstructure:"onu_type"`
@@ -442,6 +477,7 @@ type Board2Pon9 struct {
442477
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
443478
}
444479

480+
// Board2Pon10 contains OID configurations for Board 2 Port 10 ONU management.
445481
type Board2Pon10 struct {
446482
OnuIDNameOID string `mapstructure:"onu_id_name"`
447483
OnuTypeOID string `mapstructure:"onu_type"`
@@ -457,6 +493,7 @@ type Board2Pon10 struct {
457493
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
458494
}
459495

496+
// Board2Pon11 contains OID configurations for Board 2 Port 11 ONU management.
460497
type Board2Pon11 struct {
461498
OnuIDNameOID string `mapstructure:"onu_id_name"`
462499
OnuTypeOID string `mapstructure:"onu_type"`
@@ -472,6 +509,7 @@ type Board2Pon11 struct {
472509
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
473510
}
474511

512+
// Board2Pon12 contains OID configurations for Board 2 Port 12 ONU management.
475513
type Board2Pon12 struct {
476514
OnuIDNameOID string `mapstructure:"onu_id_name"`
477515
OnuTypeOID string `mapstructure:"onu_type"`
@@ -487,6 +525,7 @@ type Board2Pon12 struct {
487525
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
488526
}
489527

528+
// Board2Pon13 contains OID configurations for Board 2 Port 13 ONU management.
490529
type Board2Pon13 struct {
491530
OnuIDNameOID string `mapstructure:"onu_id_name"`
492531
OnuTypeOID string `mapstructure:"onu_type"`
@@ -502,6 +541,7 @@ type Board2Pon13 struct {
502541
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
503542
}
504543

544+
// Board2Pon14 contains OID configurations for Board 2 Port 14 ONU management.
505545
type Board2Pon14 struct {
506546
OnuIDNameOID string `mapstructure:"onu_id_name"`
507547
OnuTypeOID string `mapstructure:"onu_type"`
@@ -517,6 +557,7 @@ type Board2Pon14 struct {
517557
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
518558
}
519559

560+
// Board2Pon15 contains OID configurations for Board 2 Port 15 ONU management.
520561
type Board2Pon15 struct {
521562
OnuIDNameOID string `mapstructure:"onu_id_name"`
522563
OnuTypeOID string `mapstructure:"onu_type"`
@@ -532,6 +573,7 @@ type Board2Pon15 struct {
532573
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
533574
}
534575

576+
// Board2Pon16 contains OID configurations for Board 2 Port 16 ONU management.
535577
type Board2Pon16 struct {
536578
OnuIDNameOID string `mapstructure:"onu_id_name"`
537579
OnuTypeOID string `mapstructure:"onu_type"`

docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
app:
3-
image: sumitroajiprabowo/go-snmp-olt-zte-c320:latest
4-
container_name: go-snmp-olt-zte-c320
3+
image: cepatkilatteknologi/go-snmp-olt-zte-c320:latest
4+
container_name: snmp-olt-zte-c320
55
environment:
66
- REDIS_HOST=redis
77
- REDIS_PORT=6379
@@ -18,7 +18,7 @@ services:
1818
- "8081:8081"
1919

2020
redis:
21-
container_name: redis
21+
container_name: redis-snmp-olt-zte-c320
2222
image: redis:7.2
2323
ports:
2424
- "6379:6379"

0 commit comments

Comments
 (0)