mirror of
				https://github.com/owncast/owncast.git
				synced 2025-11-01 02:44:31 +08:00 
			
		
		
		
	Variable collisions; Possible use of nil value (#256)
* Variable '*' collides with imported package name * Variable 'error' collides with builtin interface * '*' may have 'nil' or other unexpected value as its corresponding error variable may be not 'nil'
This commit is contained in:
		| @ -9,8 +9,8 @@ import ( | |||||||
|  |  | ||||||
| // GetHardwareStats will return hardware utilization over time | // GetHardwareStats will return hardware utilization over time | ||||||
| func GetHardwareStats(w http.ResponseWriter, r *http.Request) { | func GetHardwareStats(w http.ResponseWriter, r *http.Request) { | ||||||
| 	metrics := metrics.Metrics | 	m := metrics.Metrics | ||||||
|  |  | ||||||
| 	w.Header().Set("Content-Type", "application/json") | 	w.Header().Set("Content-Type", "application/json") | ||||||
| 	json.NewEncoder(w).Encode(metrics) | 	json.NewEncoder(w).Encode(m) | ||||||
| } | } | ||||||
|  | |||||||
| @ -15,13 +15,13 @@ import ( | |||||||
|  |  | ||||||
| // Make this path configurable if somebody has a valid reason | // Make this path configurable if somebody has a valid reason | ||||||
| // to need it to be.  The config is getting a bit bloated. | // to need it to be.  The config is getting a bit bloated. | ||||||
| const emojiPath = "/img/emoji" // Relative to webroot | const emojiDir = "/img/emoji" // Relative to webroot | ||||||
|  |  | ||||||
| //GetCustomEmoji returns a list of custom emoji via the API | //GetCustomEmoji returns a list of custom emoji via the API | ||||||
| func GetCustomEmoji(w http.ResponseWriter, r *http.Request) { | func GetCustomEmoji(w http.ResponseWriter, r *http.Request) { | ||||||
| 	emojiList := make([]models.CustomEmoji, 0) | 	emojiList := make([]models.CustomEmoji, 0) | ||||||
|  |  | ||||||
| 	fullPath := filepath.Join(config.WebRoot, emojiPath) | 	fullPath := filepath.Join(config.WebRoot, emojiDir) | ||||||
| 	files, err := ioutil.ReadDir(fullPath) | 	files, err := ioutil.ReadDir(fullPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Errorln(err) | 		log.Errorln(err) | ||||||
| @ -34,8 +34,8 @@ func GetCustomEmoji(w http.ResponseWriter, r *http.Request) { | |||||||
| 	// the server to add emoji? | 	// the server to add emoji? | ||||||
| 	for _, f := range files { | 	for _, f := range files { | ||||||
| 		name := strings.TrimSuffix(f.Name(), path.Ext(f.Name())) | 		name := strings.TrimSuffix(f.Name(), path.Ext(f.Name())) | ||||||
| 		path := filepath.Join(emojiPath, f.Name()) | 		emojiPath := filepath.Join(emojiDir, f.Name()) | ||||||
| 		singleEmoji := models.CustomEmoji{name, path} | 		singleEmoji := models.CustomEmoji{name, emojiPath} | ||||||
| 		emojiList = append(emojiList, singleEmoji) | 		emojiList = append(emojiList, singleEmoji) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | |||||||
| @ -64,7 +64,13 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) { | |||||||
| 	tmpl := template.Must(template.ParseFiles(path.Join("static", "metadata.html"))) | 	tmpl := template.Must(template.ParseFiles(path.Join("static", "metadata.html"))) | ||||||
|  |  | ||||||
| 	fullURL, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, r.URL.Path)) | 	fullURL, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, r.URL.Path)) | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Panicln(err) | ||||||
|  | 	} | ||||||
| 	imageURL, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, config.Config.InstanceDetails.Logo.Large)) | 	imageURL, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, config.Config.InstanceDetails.Logo.Large)) | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Panicln(err) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	status := core.GetStatus() | 	status := core.GetStatus() | ||||||
|  |  | ||||||
| @ -74,8 +80,10 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) { | |||||||
| 		thumbnail, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, "/thumbnail.jpg")) | 		thumbnail, err := url.Parse(fmt.Sprintf("http://%s%s", r.Host, "/thumbnail.jpg")) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			log.Errorln(err) | 			log.Errorln(err) | ||||||
|  | 			thumbnailURL = imageURL.String() | ||||||
|  | 		} else { | ||||||
|  | 			thumbnailURL = thumbnail.String() | ||||||
| 		} | 		} | ||||||
| 		thumbnailURL = thumbnail.String() |  | ||||||
| 	} else { | 	} else { | ||||||
| 		thumbnailURL = imageURL.String() | 		thumbnailURL = imageURL.String() | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -50,6 +50,9 @@ func createTable(db *sql.DB) { | |||||||
|  |  | ||||||
| func addMessage(message models.ChatMessage) { | func addMessage(message models.ChatMessage) { | ||||||
| 	tx, err := _db.Begin() | 	tx, err := _db.Begin() | ||||||
|  | 	if err != nil { | ||||||
|  | 		log.Fatal(err) | ||||||
|  | 	} | ||||||
| 	stmt, err := tx.Prepare("INSERT INTO messages(id, author, body, messageType, visible, timestamp) values(?, ?, ?, ?, ?, ?)") | 	stmt, err := tx.Prepare("INSERT INTO messages(id, author, body, messageType, visible, timestamp) values(?, ?, ?, ?, ?, ?)") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatal(err) | 		log.Fatal(err) | ||||||
|  | |||||||
| @ -69,9 +69,9 @@ func (v *VideoSize) getString() string { | |||||||
|  |  | ||||||
| func (t *Transcoder) Stop() { | func (t *Transcoder) Stop() { | ||||||
| 	log.Traceln("Transcoder STOP requested.") | 	log.Traceln("Transcoder STOP requested.") | ||||||
| 	error := _commandExec.Process.Kill() | 	err := _commandExec.Process.Kill() | ||||||
| 	if error != nil { | 	if err != nil { | ||||||
| 		log.Errorln(error) | 		log.Errorln(err) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | |||||||
| @ -34,8 +34,8 @@ func Start() { | |||||||
| 	port := 1935 | 	port := 1935 | ||||||
| 	s := rtmp.NewServer() | 	s := rtmp.NewServer() | ||||||
| 	var lis net.Listener | 	var lis net.Listener | ||||||
| 	var error error | 	var err error | ||||||
| 	if lis, error = net.Listen("tcp", fmt.Sprintf(":%d", port)); error != nil { | 	if lis, err = net.Listen("tcp", fmt.Sprintf(":%d", port)); err != nil { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @ -46,8 +46,8 @@ func Start() { | |||||||
|  |  | ||||||
| 	s.HandleConn = HandleConn | 	s.HandleConn = HandleConn | ||||||
|  |  | ||||||
| 	if error != nil { | 	if err != nil { | ||||||
| 		log.Panicln(error) | 		log.Panicln(err) | ||||||
| 	} | 	} | ||||||
| 	log.Infof("RTMP server is listening for incoming stream on port: %d", port) | 	log.Infof("RTMP server is listening for incoming stream on port: %d", port) | ||||||
|  |  | ||||||
|  | |||||||
| @ -40,9 +40,9 @@ func (s *LocalStorage) SegmentWritten(localFilePath string) { | |||||||
|  |  | ||||||
| // VariantPlaylistWritten is called when a variant hls playlist is written | // VariantPlaylistWritten is called when a variant hls playlist is written | ||||||
| func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) { | func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) { | ||||||
| 	_, error := s.Save(localFilePath, 0) | 	_, err := s.Save(localFilePath, 0) | ||||||
| 	if error != nil { | 	if err != nil { | ||||||
| 		log.Errorln(error) | 		log.Errorln(err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -72,9 +72,9 @@ func (s *S3Storage) SegmentWritten(localFilePath string) { | |||||||
| 	utils.StartPerformanceMonitor(performanceMonitorKey) | 	utils.StartPerformanceMonitor(performanceMonitorKey) | ||||||
|  |  | ||||||
| 	// Upload the segment | 	// Upload the segment | ||||||
| 	_, error := s.Save(localFilePath, 0) | 	_, err := s.Save(localFilePath, 0) | ||||||
| 	if error != nil { | 	if err != nil { | ||||||
| 		log.Errorln(error) | 		log.Errorln(err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	averagePerformance := utils.GetAveragePerformance(performanceMonitorKey) | 	averagePerformance := utils.GetAveragePerformance(performanceMonitorKey) | ||||||
| @ -89,11 +89,11 @@ func (s *S3Storage) SegmentWritten(localFilePath string) { | |||||||
| 	// Upload the variant playlist for this segment | 	// Upload the variant playlist for this segment | ||||||
| 	// so the segments and the HLS playlist referencing | 	// so the segments and the HLS playlist referencing | ||||||
| 	// them are in sync. | 	// them are in sync. | ||||||
| 	playlist := filepath.Join(filepath.Dir(localFilePath), "stream.m3u8") | 	playlistPath := filepath.Join(filepath.Dir(localFilePath), "stream.m3u8") | ||||||
| 	_, error = s.Save(playlist, 0) | 	_, err = s.Save(playlistPath, 0) | ||||||
| 	if error != nil { | 	if err != nil { | ||||||
| 		_queuedPlaylistUpdates[playlist] = playlist | 		_queuedPlaylistUpdates[playlistPath] = playlistPath | ||||||
| 		if pErr, ok := error.(*os.PathError); ok { | 		if pErr, ok := err.(*os.PathError); ok { | ||||||
| 			log.Debugln(pErr.Path, "does not yet exist locally when trying to upload to S3 storage.") | 			log.Debugln(pErr.Path, "does not yet exist locally when trying to upload to S3 storage.") | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| @ -106,9 +106,9 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) { | |||||||
| 	// to make sure we're not refering to files in a playlist that don't | 	// to make sure we're not refering to files in a playlist that don't | ||||||
| 	// yet exist.  See SegmentWritten. | 	// yet exist.  See SegmentWritten. | ||||||
| 	if _, ok := _queuedPlaylistUpdates[localFilePath]; ok { | 	if _, ok := _queuedPlaylistUpdates[localFilePath]; ok { | ||||||
| 		_, error := s.Save(localFilePath, 0) | 		_, err := s.Save(localFilePath, 0) | ||||||
| 		if error != nil { | 		if err != nil { | ||||||
| 			log.Errorln(error) | 			log.Errorln(err) | ||||||
| 			_queuedPlaylistUpdates[localFilePath] = localFilePath | 			_queuedPlaylistUpdates[localFilePath] = localFilePath | ||||||
| 		} | 		} | ||||||
| 		delete(_queuedPlaylistUpdates, localFilePath) | 		delete(_queuedPlaylistUpdates, localFilePath) | ||||||
|  | |||||||
| @ -74,10 +74,10 @@ func SetStreamAsDisconnected() { | |||||||
|  |  | ||||||
| 		if utils.DoesFileExists(playlistFilePath) { | 		if utils.DoesFileExists(playlistFilePath) { | ||||||
| 			f, err := os.OpenFile(playlistFilePath, os.O_CREATE|os.O_RDWR, os.ModePerm) | 			f, err := os.OpenFile(playlistFilePath, os.O_CREATE|os.O_RDWR, os.ModePerm) | ||||||
| 			defer f.Close() |  | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				log.Errorln(err) | 				log.Errorln(err) | ||||||
| 			} | 			} | ||||||
|  | 			defer f.Close() | ||||||
|  |  | ||||||
| 			playlist, _, err := m3u8.DecodeFrom(bufio.NewReader(f), true) | 			playlist, _, err := m3u8.DecodeFrom(bufio.NewReader(f), true) | ||||||
| 			variantPlaylist := playlist.(*m3u8.MediaPlaylist) | 			variantPlaylist := playlist.(*m3u8.MediaPlaylist) | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								yp/yp.go
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								yp/yp.go
									
									
									
									
									
								
							| @ -108,12 +108,11 @@ func (yp *YP) ping() { | |||||||
|  |  | ||||||
| func (yp *YP) writeSavedKey(key string) { | func (yp *YP) writeSavedKey(key string) { | ||||||
| 	f, err := os.Create(".yp.key") | 	f, err := os.Create(".yp.key") | ||||||
| 	defer f.Close() |  | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Errorln(err) | 		log.Errorln(err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | 	defer f.Close() | ||||||
|  |  | ||||||
| 	_, err = f.WriteString(key) | 	_, err = f.WriteString(key) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 bitspill
					bitspill