Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23-alpine AS dev
FROM golang:1.25-alpine AS dev
RUN go install github.com/air-verse/air@latest
WORKDIR /app
COPY . /app/
Expand Down
19 changes: 17 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package app

import (
"context"
"net/http"
"os"

"github.com/megadata-dev/go-snmp-olt-zte-c320/config"
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/handler"
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/repository"
Expand All @@ -12,18 +15,30 @@ import (
"github.com/megadata-dev/go-snmp-olt-zte-c320/pkg/snmp"
rds "github.com/redis/go-redis/v9"
"github.com/rs/zerolog/log"
"net/http"
"os"
)

// App represents the main application structure that holds the HTTP router
// and manages the application lifecycle including dependencies initialization
// and server startup.
type App struct {
router http.Handler
}

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

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

// Get config path from APP_ENV environment variable
Expand Down
5 changes: 3 additions & 2 deletions app/routes.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app

import (
"net/http"
"os"

"github.com/go-chi/chi/v5"
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/handler"
"github.com/megadata-dev/go-snmp-olt-zte-c320/internal/middleware"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"net/http"
"os"
)

func loadRoutes(onuHandler *handler.OnuHandler) http.Handler {
Expand Down
1 change: 1 addition & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"

"github.com/megadata-dev/go-snmp-olt-zte-c320/app"
"github.com/rs/zerolog/log"
)
Expand Down
44 changes: 43 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/spf13/viper"
)

// Config represents the main application configuration structure
// that contains all sub-configurations for SNMP, Redis, OLT, and individual PON boards.
type Config struct {
SnmpCfg SnmpConfig
RedisCfg RedisConfig
Expand Down Expand Up @@ -44,12 +46,16 @@ type Config struct {
Board2Pon16 Board2Pon16
}

// SnmpConfig contains configuration parameters for SNMP connection
// including target IP address, port, and community string.
type SnmpConfig struct {
Ip string `mapstructure:"ip"`
IP string `mapstructure:"ip"` // Target IP address of the SNMP device
Port uint16 `mapstructure:"port"`
Community string `mapstructure:"community"`
}

// RedisConfig contains configuration parameters for Redis connection
// including host, port, authentication, and connection pooling settings.
type RedisConfig struct {
Host string `mapstructure:"host"`
Port string `mapstructure:"port"`
Expand All @@ -61,13 +67,17 @@ type RedisConfig struct {
PoolTimeout int `mapstructure:"pool_timeout"`
}

// OltConfig contains base OID configurations for OLT device management
// including common OIDs for ONU identification and type mapping.
type OltConfig struct {
BaseOID1 string `mapstructure:"base_oid_1"`
BaseOID2 string `mapstructure:"base_oid_2"`
OnuIDNameAllPon string `mapstructure:"onu_id_name"`
OnuTypeAllPon string `mapstructure:"onu_type"`
}

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

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

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

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

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

// Board1Pon6 contains OID configurations for Board 1 Port 6 ONU management.
type Board1Pon6 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -158,6 +173,7 @@ type Board1Pon6 struct {
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

// Board1Pon7 contains OID configurations for Board 1 Port 7 ONU management.
type Board1Pon7 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -173,6 +189,7 @@ type Board1Pon7 struct {
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

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

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

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

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

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

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

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

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

// Board1Pon16 contains OID configurations for Board 1 Port 16 ONU management.
type Board1Pon16 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -307,6 +332,8 @@ type Board1Pon16 struct {
OnuLastOfflineReasonOID string `mapstructure:"onu_last_offline_reason"`
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

// Board2Pon1 contains OID configurations for Board 2 Port 1 ONU management.
type Board2Pon1 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -322,6 +349,7 @@ type Board2Pon1 struct {
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

// Board2Pon2 contains OID configurations for Board 2 Port 2 ONU management.
type Board2Pon2 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -337,6 +365,7 @@ type Board2Pon2 struct {
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

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

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

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

// Board2Pon6 contains OID configurations for Board 2 Port 6 ONU management.
type Board2Pon6 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -397,6 +429,7 @@ type Board2Pon6 struct {
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

// Board2Pon7 contains OID configurations for Board 2 Port 7 ONU management.
type Board2Pon7 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand All @@ -412,6 +445,7 @@ type Board2Pon7 struct {
OnuGponOpticalDistanceOID string `mapstructure:"onu_gpon_optical_distance"`
}

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

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

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

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

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

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

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

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

// Board2Pon16 contains OID configurations for Board 2 Port 16 ONU management.
type Board2Pon16 struct {
OnuIDNameOID string `mapstructure:"onu_id_name"`
OnuTypeOID string `mapstructure:"onu_type"`
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
app:
image: sumitroajiprabowo/go-snmp-olt-zte-c320:latest
container_name: go-snmp-olt-zte-c320
image: cepatkilatteknologi/go-snmp-olt-zte-c320:latest
container_name: snmp-olt-zte-c320
environment:
- REDIS_HOST=redis
- REDIS_PORT=6379
Expand All @@ -18,7 +18,7 @@ services:
- "8081:8081"

redis:
container_name: redis
container_name: redis-snmp-olt-zte-c320
image: redis:7.2
ports:
- "6379:6379"
Loading
Loading