Skip to content

Commit 9fec74c

Browse files
committed
Unexport Symbols
If symbols aren't used in another package unexport them
1 parent ed0299a commit 9fec74c

File tree

24 files changed

+93
-175
lines changed

24 files changed

+93
-175
lines changed

internal/environment/environment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func LoadEnvironmentVariables() {
4343
}
4444

4545
func loadConfigs() error {
46-
if os.Getenv(AppEnv) == "development" {
46+
if os.Getenv(appEnv) == "development" {
4747
log.Println("Environment: Loading `" + envFileDevelopment + "`")
4848
if err := godotenv.Load(envFileDevelopment); err != nil {
4949
log.Printf("Environment: Could not load `%s`: %v", envFileDevelopment, err)
@@ -68,7 +68,7 @@ func loadConfigs() error {
6868
}
6969

7070
func GetFrontendPath() string {
71-
frontendPath := os.Getenv(FrontendPath)
71+
frontendPath := os.Getenv(frontendPath)
7272
if frontendPath == "" {
7373
return defaultFrontendPath
7474
}

internal/environment/logger.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
)
2020

2121
func SetupLogger() {
22-
if strings.EqualFold(os.Getenv(LoggingEnabled), "false") {
22+
if strings.EqualFold(os.Getenv(loggingEnabled), "false") {
2323
return
2424
}
2525

@@ -74,7 +74,7 @@ func getLogFileWriter() (logFile *os.File, err error) {
7474
log.Fatalf("Failed to create log directory: %v", err)
7575
}
7676

77-
if envLogTruncateExistingFile := strings.EqualFold(os.Getenv(LoggingNewFileOnStartup), "true"); envLogTruncateExistingFile {
77+
if envLogTruncateExistingFile := strings.EqualFold(os.Getenv(loggingNewFileOnStartup), "true"); envLogTruncateExistingFile {
7878
logFile, err = os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
7979
} else {
8080
logFile, err = os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
@@ -91,13 +91,13 @@ func getLogFileWriter() (logFile *os.File, err error) {
9191

9292
func getLogfilePath() (directory string, fileName string, logFilePath string) {
9393
logDir := "logs"
94-
if envLogDir := os.Getenv(LoggingDirectory); envLogDir != "" {
94+
if envLogDir := os.Getenv(loggingDirectory); envLogDir != "" {
9595
logDir = envLogDir
9696
}
9797

9898
logFileName := time.Now().Format("20060102")
9999

100-
if envLogFileIsSingleFile := strings.EqualFold(os.Getenv(LoggingSingleFile), "true"); envLogFileIsSingleFile {
100+
if envLogFileIsSingleFile := strings.EqualFold(os.Getenv(loggingSingleFile), "true"); envLogFileIsSingleFile {
101101
logFileName = "log"
102102
}
103103

internal/environment/variables.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package environment
22

33
const (
44
// SERVER
5-
AppEnv = "APP_ENV"
5+
appEnv = "APP_ENV"
66
HTTPAddress = "HTTP_ADDRESS"
77
HTTPSRedirectPort = "HTTPS_REDIRECT_PORT"
88
HTTPEnableRedirect = "ENABLE_HTTP_REDIRECT"
@@ -12,7 +12,7 @@ const (
1212
EnableProfiling = "ENABLE_PROFILING"
1313

1414
// SSL
15-
UseSSL = "USE_SSL"
15+
useSSL = "USE_SSL"
1616
SSLKey = "SSL_KEY"
1717
SSLCert = "SSL_CERT"
1818

@@ -23,7 +23,7 @@ const (
2323

2424
// FRONTEND
2525
FrontendDisabled = "DISABLE_FRONTEND"
26-
FrontendPath = "FRONTEND_PATH"
26+
frontendPath = "FRONTEND_PATH"
2727
FrontendAdminToken = "FRONTEND_ADMIN_TOKEN"
2828

2929
// WEBRTC
@@ -51,10 +51,10 @@ const (
5151
DebugPrintSSEMessages = "DEBUG_PRINT_SSE_MESSAGES"
5252

5353
// LOGGING
54-
LoggingEnabled = "LOGGING_ENABLED"
55-
LoggingDirectory = "LOGGING_DIRECTORY"
56-
LoggingSingleFile = "LOGGING_SINGLEFILE"
57-
LoggingNewFileOnStartup = "LOGGING_NEW_FILE_ON_STARTUP"
54+
loggingEnabled = "LOGGING_ENABLED"
55+
loggingDirectory = "LOGGING_DIRECTORY"
56+
loggingSingleFile = "LOGGING_SINGLEFILE"
57+
loggingNewFileOnStartup = "LOGGING_NEW_FILE_ON_STARTUP"
5858
LoggingAPIEnabled = "LOGGING_API_ENABLED"
5959
LoggingAPIKey = "LOGGING_API_KEY"
6060
)

internal/server/authorization/stream_profile.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const (
15-
StreamPolicyAnyone = "ANYONE"
15+
streamPolicyAnyone = "ANYONE"
1616
StreamPolicyWithReserved = "ANYONE_WITH_RESERVED"
1717
StreamPolicyReservedOnly = "RESERVED"
1818
)
@@ -41,7 +41,7 @@ func CreateProfile(streamKey string) (string, error) {
4141

4242
fileName := streamKey + "_" + token
4343
profileFilePath := filepath.Join(profilePath, fileName)
44-
profile := Profile{
44+
profile := profile{
4545
FileName: fileName,
4646
IsPublic: true,
4747
MOTD: "Welcome to " + streamKey + "!",
@@ -67,7 +67,7 @@ func CreateProfile(streamKey string) (string, error) {
6767
// Update a current profile
6868
func UpdateProfile(token string, motd string, isPublic bool) error {
6969
if !hasExistingBearerToken(token) {
70-
return fmt.Errorf("Profile was not found")
70+
return fmt.Errorf("profile was not found")
7171
}
7272

7373
profile, err := GetPersonalProfile(token)
@@ -116,7 +116,7 @@ func RemoveProfile(streamKey string) (bool, error) {
116116
fileName, _ := getProfileFileNameByStreamKey(streamKey)
117117
if fileName == "" {
118118
log.Println("Authorization: RemoveProfile could not find", streamKey)
119-
return false, fmt.Errorf("Profile could not be found")
119+
return false, fmt.Errorf("profile could not be found")
120120
}
121121

122122
profilePath := os.Getenv(environment.StreamProfilePath)
@@ -143,14 +143,14 @@ func GetPublicProfile(bearerToken string) (*PublicProfile, error) {
143143
return nil, err
144144
}
145145

146-
var profile Profile
146+
var profile profile
147147
if err := json.Unmarshal(data, &profile); err != nil {
148148
log.Println("Authorization: File", bearerToken, "could not read. File may be corrupt.")
149149
return nil, err
150150
}
151151
profile.FileName = fileName
152152

153-
return profile.AsPublicProfile(), nil
153+
return profile.asPublicProfile(), nil
154154
}
155155

156156
// Returns the publicly available profile
@@ -168,18 +168,18 @@ func GetPersonalProfile(bearerToken string) (*PersonalProfile, error) {
168168
return nil, err
169169
}
170170

171-
var profile Profile
171+
var profile profile
172172
if err := json.Unmarshal(data, &profile); err != nil {
173173
log.Println("Authorization: File", bearerToken, "could not read. File may be corrupt.")
174174
return nil, err
175175
}
176176
profile.FileName = fileName
177177

178-
return profile.AsPersonalProfile(), nil
178+
return profile.asPersonalProfile(), nil
179179
}
180180

181181
// Returns a slice of profiles intended for admin endpoints
182-
func GetAdminProfilesAll() (profiles []AdminProfile, err error) {
182+
func GetAdminProfilesAll() (profiles []adminProfile, err error) {
183183
profilePath := os.Getenv(environment.StreamProfilePath)
184184

185185
files, err := os.ReadDir(profilePath)
@@ -191,7 +191,7 @@ func GetAdminProfilesAll() (profiles []AdminProfile, err error) {
191191
for _, file := range files {
192192
data, err := os.ReadFile(filepath.Join(profilePath, file.Name()))
193193
if err != nil {
194-
profiles = append(profiles, AdminProfile{
194+
profiles = append(profiles, adminProfile{
195195
StreamKey: file.Name(),
196196
IsPublic: false,
197197
MOTD: "Error reading profile from file: " + file.Name(),
@@ -200,10 +200,10 @@ func GetAdminProfilesAll() (profiles []AdminProfile, err error) {
200200
continue
201201
}
202202

203-
var profile Profile
203+
var profile profile
204204

205205
if err := json.Unmarshal(data, &profile); err != nil {
206-
profiles = append(profiles, AdminProfile{
206+
profiles = append(profiles, adminProfile{
207207
StreamKey: file.Name(),
208208
IsPublic: false,
209209
MOTD: "Invalid JSON in file" + file.Name(),
@@ -212,7 +212,7 @@ func GetAdminProfilesAll() (profiles []AdminProfile, err error) {
212212
}
213213

214214
profile.FileName = file.Name()
215-
profiles = append(profiles, *profile.AsAdminProfile())
215+
profiles = append(profiles, *profile.asAdminProfile())
216216
}
217217

218218
return profiles, nil

internal/server/authorization/stream_profile_types.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"strings"
55
)
66

7-
// Internal Profile struct, do not use for endpoints
8-
type Profile struct {
7+
// Internal profile struct, do not use for endpoints
8+
type profile struct {
99
FileName string
1010
IsActive bool
1111
IsPublic bool
@@ -14,34 +14,34 @@ type Profile struct {
1414

1515
var separator = "_"
1616

17-
func (p *Profile) StreamKey() string {
17+
func (p *profile) streamKey() string {
1818
splitIndex := strings.LastIndex(p.FileName, separator)
1919
return p.FileName[:splitIndex+len(separator)-1]
2020
}
21-
func (p *Profile) StreamToken() string {
21+
func (p *profile) streamToken() string {
2222
splitIndex := strings.LastIndex(p.FileName, separator)
2323
return p.FileName[splitIndex+len(separator):]
2424
}
25-
func (p *Profile) AsPublicProfile() *PublicProfile {
25+
func (p *profile) asPublicProfile() *PublicProfile {
2626
return &PublicProfile{
27-
StreamKey: p.StreamKey(),
27+
StreamKey: p.streamKey(),
2828
IsActive: p.IsActive,
2929
IsPublic: p.IsPublic,
3030
MOTD: p.MOTD,
3131
}
3232
}
33-
func (p *Profile) AsPersonalProfile() *PersonalProfile {
33+
func (p *profile) asPersonalProfile() *PersonalProfile {
3434
return &PersonalProfile{
35-
StreamKey: p.StreamKey(),
35+
StreamKey: p.streamKey(),
3636
IsActive: p.IsActive,
3737
IsPublic: p.IsPublic,
3838
MOTD: p.MOTD,
3939
}
4040
}
41-
func (p *Profile) AsAdminProfile() *AdminProfile {
42-
return &AdminProfile{
43-
StreamKey: p.StreamKey(),
44-
Token: p.StreamToken(),
41+
func (p *profile) asAdminProfile() *adminProfile {
42+
return &adminProfile{
43+
StreamKey: p.streamKey(),
44+
Token: p.streamToken(),
4545
IsPublic: p.IsPublic,
4646
MOTD: p.MOTD,
4747
}
@@ -64,7 +64,7 @@ type PersonalProfile struct {
6464
}
6565

6666
// Admin profile struct for serving to admin specific endpoints
67-
type AdminProfile struct {
67+
type adminProfile struct {
6868
StreamKey string `json:"streamKey"`
6969
Token string `json:"token"`
7070
IsPublic bool `json:"isPublic"`

internal/server/handlers/admin/helpers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ import (
1111
"github.com/glimesh/broadcast-box/internal/server/helpers"
1212
)
1313

14-
type SessionResponse struct {
14+
type sessionResponse struct {
1515
IsValid bool `json:"isValid"`
1616
ErrorMessage string `json:"errorMessage"`
1717
}
1818

1919
// Verify that a bearer token is provided for an admin session
2020
// A response will be written to the response writter if the session is valid
21-
func verifyAdminSession(request *http.Request) *SessionResponse {
21+
func verifyAdminSession(request *http.Request) *sessionResponse {
2222
token := helpers.ResolveBearerToken(request.Header.Get("Authorization"))
2323
if token == "" {
2424
log.Println("Authorization was not set")
2525

26-
return &SessionResponse{
26+
return &sessionResponse{
2727
IsValid: false,
2828
ErrorMessage: "Authorization was invalid",
2929
}
@@ -32,13 +32,13 @@ func verifyAdminSession(request *http.Request) *SessionResponse {
3232
adminAPIToken := os.Getenv(environment.FrontendAdminToken)
3333

3434
if adminAPIToken == "" || !strings.EqualFold(adminAPIToken, token) {
35-
return &SessionResponse{
35+
return &sessionResponse{
3636
IsValid: false,
3737
ErrorMessage: "Authorization was invalid",
3838
}
3939
}
4040

41-
return &SessionResponse{
41+
return &sessionResponse{
4242
IsValid: true,
4343
ErrorMessage: "",
4444
}
@@ -49,7 +49,7 @@ func verifyAdminSession(request *http.Request) *SessionResponse {
4949
func verifyValidMethod(expectedMethod string, responseWriter http.ResponseWriter, request *http.Request) bool {
5050
if !strings.EqualFold(expectedMethod, request.Method) {
5151
helpers.LogHTTPError(responseWriter, "Method not allowed", http.StatusMethodNotAllowed)
52-
err := json.NewEncoder(responseWriter).Encode(&SessionResponse{
52+
err := json.NewEncoder(responseWriter).Encode(&sessionResponse{
5353
IsValid: false,
5454
ErrorMessage: "Method not allowed",
5555
})

internal/server/handlers/routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ func GetServeMuxHandler() http.HandlerFunc {
2121
}
2222

2323
// WHIP/WHEP shared endpoints
24-
serverMux.HandleFunc("/api/whep", corsHandler(WHEPHandler))
25-
serverMux.HandleFunc("/api/whep/", corsHandler(WHEPHandler))
24+
serverMux.HandleFunc("/api/whep", corsHandler(whepHandler))
25+
serverMux.HandleFunc("/api/whep/", corsHandler(whepHandler))
2626
serverMux.HandleFunc("/api/sse/", corsHandler(sseHandler))
2727

2828
// WHIP session endpoints

internal/server/handlers/whep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/glimesh/broadcast-box/internal/webrtc/utils"
1717
)
1818

19-
func WHEPHandler(responseWriter http.ResponseWriter, request *http.Request) {
19+
func whepHandler(responseWriter http.ResponseWriter, request *http.Request) {
2020
if request.Method != http.MethodPost && request.Method != http.MethodPatch {
2121
helpers.LogHTTPError(responseWriter, "Method not allowed", http.StatusMethodNotAllowed)
2222
return

internal/server/handlers/whep_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestWHEPHandlerCallsWebhook(t *testing.T) {
4141
req.RemoteAddr = "203.0.113.10:1234"
4242

4343
resp := httptest.NewRecorder()
44-
WHEPHandler(resp, req)
44+
whepHandler(resp, req)
4545

4646
if resp.Code != http.StatusUnauthorized {
4747
t.Fatalf("expected status %d, got %d", http.StatusUnauthorized, resp.Code)

internal/server/webhook/webhook.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
const defaultTimeout = time.Second * 5
1313

1414
type webhookPayload struct {
15-
Action Action `json:"action"`
15+
Action action `json:"action"`
1616
IP string `json:"ip"`
1717
BearerToken string `json:"bearerToken"`
1818
QueryParams map[string]string `json:"queryParams"`
@@ -23,14 +23,14 @@ type webhookResponse struct {
2323
StreamKey string `json:"streamKey"`
2424
}
2525

26-
type Action string
26+
type action string
2727

2828
const (
29-
WHIPConnect Action = "whip-connect"
30-
WHEPConnect Action = "whep-connect"
29+
WHIPConnect action = "whip-connect"
30+
WHEPConnect action = "whep-connect"
3131
)
3232

33-
func CallWebhook(url string, action Action, bearerToken string, request *http.Request) (string, error) {
33+
func CallWebhook(url string, action action, bearerToken string, request *http.Request) (string, error) {
3434
start := time.Now()
3535

3636
queryParams := make(map[string]string)

0 commit comments

Comments
 (0)