Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golangci config and workflow #62

Merged
merged 12 commits into from
Jan 12, 2023
23 changes: 23 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: golangci-lint
on:
push:
branches: ["master","dev"]
pull_request:
branches: ["master","dev"]
jobs:
golangci:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19
- uses: actions/checkout@v3
- name: Tidy
run: go mod tidy
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
args: --timeout=3m
2 changes: 2 additions & 0 deletions configs/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
issues:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this file will do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.golangci.yml is a configuration file used by golangci-lint

It can be used to mold the linter as per our repo needs

new: true
11 changes: 4 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ import (
"zestream-server/configs"
"zestream-server/constants"
"zestream-server/routes"
"zestream-server/service"
)

func dev() {
// utils.Fetch("https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WeAreGoingOnBullrun.mp4", "Test.mp4")
service.GenerateDash("Test.mp4", constants.WaterMark{FileName: "TestWatermark.png", Dimension: map[string]int{"x": 64, "y": -1}, Position: map[string]int{"x": 10, "y": 10}}, false)
}

func main() {
configs.LoadEnv()

Expand Down Expand Up @@ -45,5 +39,8 @@ func main() {
fmt.Println(err)
}

r.Run(":" + port)
err = r.Run(":" + port)
if err != nil {
fmt.Println(err)
}
}
20 changes: 17 additions & 3 deletions service/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func generateThumbnailFiles(targetFile string, outputPath string, wg *sync.WaitG
}

func generateMultiBitrateAudio(targetFile string, outputFile string, fileType constants.FILE_TYPE, wg *sync.WaitGroup) {
ffmpeg.Input(targetFile, ffmpeg.KwArgs{
err := ffmpeg.Input(targetFile, ffmpeg.KwArgs{
constants.AudioKwargs[constants.HWAccel]: constants.FFmpegConfig[constants.HWAccel],
}).
Output(outputFile, ffmpeg.KwArgs{
Expand All @@ -78,13 +78,17 @@ func generateMultiBitrateAudio(targetFile string, outputFile string, fileType co
constants.AudioKwargs[constants.VideoExclusion]: constants.FFmpegConfig[constants.VideoExclusion],
}).
OverWriteOutput().ErrorToStdOut().Run()
if err != nil {
m := "error generating multi bitrate audio"
log.Println(m, err)
}

wg.Done()
}

func generateMultiBitrateVideo(targetFile string, outputFile string, fileType constants.FILE_TYPE, withWatermark bool, watermark constants.WaterMark, wg *sync.WaitGroup) {

getInput(targetFile, withWatermark, watermark).
err := getInput(targetFile, withWatermark, watermark).
Output(outputFile, ffmpeg.KwArgs{
constants.VideoKwargs[constants.Preset]: constants.FFmpegConfig[constants.Preset],
constants.VideoKwargs[constants.Tune]: constants.FFmpegConfig[constants.Tune],
Expand All @@ -99,12 +103,17 @@ func generateMultiBitrateVideo(targetFile string, outputFile string, fileType co
ErrorToStdOut().
Run()

if err != nil {
m := "error generating multi bitrate video"
log.Println(m, err)
}

wg.Done()
}

// generateThumbnail generates a thumbnail at given timestamp, from the target file and write it to output file
func generateThumbnails(targetFile string, outputFile string, timeStamp string, wg *sync.WaitGroup) {
ffmpeg.Input(targetFile).
err := ffmpeg.Input(targetFile).
Output(outputFile, ffmpeg.KwArgs{
constants.VideoKwargs[constants.ScreenShot]: timeStamp,
constants.VideoKwargs[constants.VideoFrames]: constants.FFmpegConfig[constants.VideoFrames],
Expand All @@ -113,6 +122,11 @@ func generateThumbnails(targetFile string, outputFile string, timeStamp string,
ErrorToStdOut().
Run()

if err != nil {
m := "error generating thumbnail"
log.Println(m, err)
}

wg.Done()
}

Expand Down
5 changes: 4 additions & 1 deletion utils/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ func TestFetch(t *testing.T) {
t.Error("want true, got", isFileDownloaded)
}

utils.DeleteFiles(pathName)
err = utils.DeleteFiles(pathName)
if err != nil {
t.Fatal(err)
}
}
5 changes: 4 additions & 1 deletion utils/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func PublishMessage(kafkaURI, topic string, message string) (string, error) {
return m, err
}

conn.SetWriteDeadline(time.Now().Add(10 * time.Second))
if err := conn.SetWriteDeadline(time.Now().Add(10 * time.Second)); err != nil {
m = "failed to set write deadline"
log.Println(m, err)
}
_, err = conn.WriteMessages(
kafka.Message{Value: []byte(message)},
)
Expand Down