Expanded linting + fix warnings (#1396)
* Expand the linters and types of warnings to improve consistency and safety * Fail lint workflow if there are errors * golint has been replaced by revive * Hand-pick some of the default exclude list * Ignore error when trying to delete preview gif * Ignore linter warning opening playlist path * Rename user field Id -> ID * A bunch of renames to address linter warnings * Rename ChatClient -> Client per linter suggestion best practice * Rename ChatServer -> Server per linter suggestion best practice * More linter warning fixes * Add missing comments to all exported functions and properties
This commit is contained in:
@@ -49,6 +49,7 @@ func UpdateMessageVisibility(w http.ResponseWriter, r *http.Request) {
|
||||
controllers.WriteSimpleResponse(w, true, "changed")
|
||||
}
|
||||
|
||||
// UpdateUserEnabled enable or disable a single user by ID.
|
||||
func UpdateUserEnabled(w http.ResponseWriter, r *http.Request) {
|
||||
type blockUserRequest struct {
|
||||
UserID string `json:"userId"`
|
||||
@@ -77,7 +78,7 @@ func UpdateUserEnabled(w http.ResponseWriter, r *http.Request) {
|
||||
// Hide/show the user's chat messages if disabling.
|
||||
// Leave hidden messages hidden to be safe.
|
||||
if !request.Enabled {
|
||||
if err := chat.SetMessageVisibilityForUserId(request.UserID, request.Enabled); err != nil {
|
||||
if err := chat.SetMessageVisibilityForUserID(request.UserID, request.Enabled); err != nil {
|
||||
log.Errorln("error changing user messages visibility", err)
|
||||
}
|
||||
}
|
||||
@@ -85,13 +86,14 @@ func UpdateUserEnabled(w http.ResponseWriter, r *http.Request) {
|
||||
// Forcefully disconnect the user from the chat
|
||||
if !request.Enabled {
|
||||
chat.DisconnectUser(request.UserID)
|
||||
disconnectedUser := user.GetUserById(request.UserID)
|
||||
disconnectedUser := user.GetUserByID(request.UserID)
|
||||
_ = chat.SendSystemAction(fmt.Sprintf("**%s** has been removed from chat.", disconnectedUser.DisplayName), true)
|
||||
}
|
||||
|
||||
controllers.WriteSimpleResponse(w, true, fmt.Sprintf("%s enabled: %t", request.UserID, request.Enabled))
|
||||
}
|
||||
|
||||
// GetDisabledUsers will return all the disabled users.
|
||||
func GetDisabledUsers(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
@@ -130,6 +132,7 @@ func SendUserMessage(integration user.ExternalAPIUser, w http.ResponseWriter, r
|
||||
controllers.BadRequestHandler(w, errors.New("no longer supported. see /api/integrations/chat/send"))
|
||||
}
|
||||
|
||||
// SendIntegrationChatMessage will send a chat message on behalf of an external chat integration.
|
||||
func SendIntegrationChatMessage(integration user.ExternalAPIUser, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
@@ -155,7 +158,7 @@ func SendIntegrationChatMessage(integration user.ExternalAPIUser, w http.Respons
|
||||
}
|
||||
|
||||
event.User = &user.User{
|
||||
Id: integration.Id,
|
||||
ID: integration.ID,
|
||||
DisplayName: name,
|
||||
DisplayColor: integration.DisplayColor,
|
||||
CreatedAt: integration.CreatedAt,
|
||||
|
||||
@@ -72,6 +72,7 @@ func SetStreamTitle(w http.ResponseWriter, r *http.Request) {
|
||||
controllers.WriteSimpleResponse(w, true, "changed")
|
||||
}
|
||||
|
||||
// ExternalSetStreamTitle will change the stream title on behalf of an external integration API request.
|
||||
func ExternalSetStreamTitle(integration user.ExternalAPIUser, w http.ResponseWriter, r *http.Request) {
|
||||
SetStreamTitle(w, r)
|
||||
}
|
||||
@@ -298,11 +299,12 @@ func SetWebServerPort(w http.ResponseWriter, r *http.Request) {
|
||||
if err := data.SetHTTPPortNumber(port); err != nil {
|
||||
controllers.WriteSimpleResponse(w, false, err.Error())
|
||||
return
|
||||
} else {
|
||||
controllers.WriteSimpleResponse(w, true, "HTTP port set")
|
||||
return
|
||||
}
|
||||
|
||||
controllers.WriteSimpleResponse(w, true, "HTTP port set")
|
||||
return
|
||||
}
|
||||
|
||||
controllers.WriteSimpleResponse(w, false, "Invalid type or value, port must be a number")
|
||||
}
|
||||
|
||||
@@ -322,14 +324,14 @@ func SetWebServerIP(w http.ResponseWriter, r *http.Request) {
|
||||
if err := data.SetHTTPListenAddress(ip.String()); err != nil {
|
||||
controllers.WriteSimpleResponse(w, false, err.Error())
|
||||
return
|
||||
} else {
|
||||
controllers.WriteSimpleResponse(w, true, "HTTP listen address set")
|
||||
return
|
||||
}
|
||||
} else {
|
||||
controllers.WriteSimpleResponse(w, false, "Invalid IP address")
|
||||
|
||||
controllers.WriteSimpleResponse(w, true, "HTTP listen address set")
|
||||
return
|
||||
}
|
||||
|
||||
controllers.WriteSimpleResponse(w, false, "Invalid IP address")
|
||||
return
|
||||
}
|
||||
controllers.WriteSimpleResponse(w, false, "Invalid type or value, IP address must be a string")
|
||||
}
|
||||
@@ -427,7 +429,7 @@ func SetS3Configuration(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if newS3Config.Value.Enabled {
|
||||
if newS3Config.Value.Endpoint == "" || !utils.IsValidUrl((newS3Config.Value.Endpoint)) {
|
||||
if newS3Config.Value.Endpoint == "" || !utils.IsValidURL((newS3Config.Value.Endpoint)) {
|
||||
controllers.WriteSimpleResponse(w, false, "s3 support requires an endpoint")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func RegisterAnonymousChatUser(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
type registerAnonymousUserResponse struct {
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
AccessToken string `json:"accessToken"`
|
||||
DisplayName string `json:"displayName"`
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func RegisterAnonymousChatUser(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
response := registerAnonymousUserResponse{
|
||||
Id: newUser.Id,
|
||||
ID: newUser.ID,
|
||||
AccessToken: newUser.AccessToken,
|
||||
DisplayName: newUser.DisplayName,
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Use this as an opportunity to mark this viewer as active.
|
||||
id := utils.GenerateClientIDFromRequest(r)
|
||||
core.SetViewerIdActive(id)
|
||||
core.SetViewerIDActive(id)
|
||||
}
|
||||
|
||||
// Set a cache control max-age header
|
||||
@@ -86,8 +86,8 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
scheme := "http"
|
||||
|
||||
if siteUrl := data.GetServerURL(); siteUrl != "" {
|
||||
if parsed, err := url.Parse(siteUrl); err == nil && parsed.Scheme != "" {
|
||||
if siteURL := data.GetServerURL(); siteURL != "" {
|
||||
if parsed, err := url.Parse(siteURL); err == nil && parsed.Scheme != "" {
|
||||
scheme = parsed.Scheme
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,5 +94,5 @@ func writeBytesAsImage(data []byte, contentType string, w http.ResponseWriter, c
|
||||
}
|
||||
|
||||
func getImage(path string) ([]byte, error) {
|
||||
return ioutil.ReadFile(path)
|
||||
return ioutil.ReadFile(path) // nolint
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import (
|
||||
"github.com/owncast/owncast/utils"
|
||||
)
|
||||
|
||||
// Ping is fired by a client to show they are still an active viewer.
|
||||
func Ping(w http.ResponseWriter, r *http.Request) {
|
||||
id := utils.GenerateClientIDFromRequest(r)
|
||||
core.SetViewerIdActive(id)
|
||||
core.SetViewerIDActive(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user