Skip to content

Commit

Permalink
refactor: interface design
Browse files Browse the repository at this point in the history
  • Loading branch information
yccodr committed Apr 25, 2024
1 parent 99a72d3 commit 50d344e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package sbi

import (
"net/http"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package sbi

import (
"net/http"
Expand Down
13 changes: 0 additions & 13 deletions internal/sbi/nssf.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/sbi/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
type Nssf interface {
Config() *factory.Config
Context() *nssf_context.NSSFContext
Processor() *Processor
}

type Processor struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/server/router.go → internal/sbi/router.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package sbi

import (
"github.com/gin-gonic/gin"
Expand Down
26 changes: 20 additions & 6 deletions internal/sbi/server/server.go → internal/sbi/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package sbi

import (
"context"
Expand All @@ -9,22 +9,32 @@ import (

"github.com/gin-gonic/gin"

nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/sbi"
"github.com/free5gc/nssf/internal/sbi/processor"
"github.com/free5gc/nssf/pkg/factory"
"github.com/free5gc/util/httpwrapper"
logger_util "github.com/free5gc/util/logger"
)

type Nssf interface {
Config() *factory.Config
Context() *nssf_context.NSSFContext
}

type Server struct {
sbi.Nssf
Nssf

httpServer *http.Server
router *gin.Engine
processor *processor.Processor
}

func NewServer(nssf sbi.Nssf, tlsKeyLogPath string) *Server {
s := &Server{Nssf: nssf}
func NewServer(nssf Nssf, tlsKeyLogPath string) *Server {
s := &Server{
Nssf: nssf,
processor: processor.NewProcessor(nssf),
}

s.router = newRouter(s)

Expand All @@ -39,6 +49,10 @@ func NewServer(nssf sbi.Nssf, tlsKeyLogPath string) *Server {
return s
}

func (s *Server) Processor() *processor.Processor {
return s.processor
}

func (s *Server) Run(wg *sync.WaitGroup) {
logger.SBILog.Info("Starting server...")

Expand Down Expand Up @@ -73,7 +87,7 @@ func (s *Server) shutdownHttpServer() {
}
}

func bindRouter(nssf sbi.Nssf, router *gin.Engine, tlsKeyLogPath string) (*http.Server, error) {
func bindRouter(nssf Nssf, router *gin.Engine, tlsKeyLogPath string) (*http.Server, error) {
sbiConfig := nssf.Config().Configuration.Sbi
bindAddr := fmt.Sprintf("%s:%d", sbiConfig.BindingIPv4, sbiConfig.Port)

Expand Down
21 changes: 8 additions & 13 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@ import (
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/sbi"
"github.com/free5gc/nssf/internal/sbi/consumer"
"github.com/free5gc/nssf/internal/sbi/processor"
"github.com/free5gc/nssf/internal/sbi/server"
"github.com/free5gc/nssf/pkg/factory"
)

type App interface {
Config() *factory.Config
Context() *nssf_context.NSSFContext
}

type NssfApp struct {
cfg *factory.Config
nssfCtx *nssf_context.NSSFContext

wg sync.WaitGroup
sbiServer *server.Server
processor *processor.Processor
sbiServer *sbi.Server
}

var _ sbi.Nssf = &NssfApp{}
var _ App = &NssfApp{}

func NewApp(cfg *factory.Config, tlsKeyLogPath string) (*NssfApp, error) {
nssf := &NssfApp{cfg: cfg, wg: sync.WaitGroup{}}
nssf.SetLogEnable(cfg.GetLogEnable())
nssf.SetLogLevel(cfg.GetLogLevel())
nssf.SetReportCaller(cfg.GetLogReportCaller())

processor := processor.NewProcessor(nssf)
nssf.processor = processor

sbiServer := server.NewServer(nssf, tlsKeyLogPath)
sbiServer := sbi.NewServer(nssf, tlsKeyLogPath)
nssf.sbiServer = sbiServer

nssf_context.Init()
Expand All @@ -60,10 +59,6 @@ func (a *NssfApp) Context() *nssf_context.NSSFContext {
return a.nssfCtx
}

func (a *NssfApp) Processor() *processor.Processor {
return a.processor
}

func (a *NssfApp) SetLogEnable(enable bool) {
logger.MainLog.Infof("Log enable is set to [%v]", enable)
if enable && logger.Log.Out == os.Stderr {
Expand Down

0 comments on commit 50d344e

Please sign in to comment.