Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 2, 2023. It is now read-only.
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
27 changes: 18 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ clean:

go_deps:
go mod download
go generate ./...

build: go_deps
go build -o bin/biz $(GO_LDFLAGS) cmd/biz/main.go
go build -o bin/app-biz $(GO_LDFLAGS) apps/biz/main.go
go build -o bin/islb $(GO_LDFLAGS) cmd/islb/main.go
go build -o bin/sfu $(GO_LDFLAGS) cmd/sfu/main.go
go build -o bin/avp $(GO_LDFLAGS) cmd/avp/main.go
go build -o bin/signal $(GO_LDFLAGS) cmd/signal/main.go

start-bin:

start-services:
Expand All @@ -36,11 +37,19 @@ test: go_deps start-services
-timeout 120s \
-coverpkg=${GO_COVERPKGS} -coverprofile=cover.out -covermode=atomic \
-v -race ${GO_TESTPKGS}
proto:
docker build -t protoc-builder ./protos && \
docker run -v $(CURDIR):/workspace protoc-builder \
protoc \
--go_opt=module=github.com/pion/ion --go_out=. \
--go-grpc_opt=module=github.com/pion/ion --go-grpc_out=. \
protos/*.proto

proto-gen-from-docker:
docker build -t go-protoc ./proto
docker run -v $(CURDIR):/workspace go-protoc proto

proto: proto_ion proto_biz

proto_ion:
protoc proto/ion/ion.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/debug/debug.proto --experimental_allow_proto3_optional --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/sfu/sfu.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/islb/islb.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
protoc proto/rtc/rtc.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.

proto_biz:
protoc apps/biz/proto/biz.proto --go_opt=module=github.com/pion/ion --go_out=. --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=.
8 changes: 8 additions & 0 deletions apps/biz/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

// ============================================================================
// GO
// ============================================================================
// GRPC & Protobuf
//go:generate /usr/bin/env bash -c "echo 'Generating [biz] protobuf and grpc services for Go, outdir=$OUTDIR'"
//go:generate protoc ./proto/biz.proto -I./proto -I../../ --go_opt=module=github.com/pion/ion --go_out=../../$OUTDIR --go-grpc_opt=module=github.com/pion/ion --go-grpc_out=../../$OUTDIR
90 changes: 90 additions & 0 deletions apps/biz/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Package cmd contains an entrypoint for running an ion-sfu instance.
package main

import (
"flag"
"fmt"
"os"

log "github.com/pion/ion-log"
biz "github.com/pion/ion/apps/biz/server"
"github.com/spf13/viper"
)

var (
conf = biz.Config{}
file string
)

func showHelp() {
fmt.Printf("Usage:%s {params}\n", os.Args[0])
fmt.Println(" -c {config file}")
fmt.Println(" -h (show help info)")
}

func unmarshal(rawVal interface{}) bool {
if err := viper.Unmarshal(rawVal); err != nil {
fmt.Printf("config file %s loaded failed. %v\n", file, err)
return false
}
return true
}

func load() bool {
_, err := os.Stat(file)
if err != nil {
return false
}

viper.SetConfigFile(file)
viper.SetConfigType("toml")

err = viper.ReadInConfig()
if err != nil {
fmt.Printf("config file %s read failed. %v\n", file, err)
return false
}

if !unmarshal(&conf) {
return false
}
if err != nil {
fmt.Printf("config file %s loaded failed. %v\n", file, err)
return false
}

fmt.Printf("config %s load ok!\n", file)

return true
}

func parse() bool {
flag.StringVar(&file, "c", "configs/biz.toml", "config file")
help := flag.Bool("h", false, "help info")
flag.Parse()
if !load() {
return false
}

if *help {
showHelp()
return false
}
return true
}

func main() {
if !parse() {
showHelp()
os.Exit(-1)
}
log.Init(conf.Log.Level)
log.Infof("--- Starting Biz Node ---")
node := biz.NewBIZ(conf.Node.NID)
if err := node.Start(conf); err != nil {
log.Errorf("biz init start: %v", err)
os.Exit(-1)
}
defer node.Close()
select {}
}
Loading