mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 10:18:59 +02:00
simplify task package implementation
This commit is contained in:
22
internal/net/http/accesslog/file_logger.go
Normal file
22
internal/net/http/accesslog/file_logger.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package accesslog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
*os.File
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func NewFileAccessLogger(parent task.Parent, cfg *Config) (*AccessLogger, error) {
|
||||
f, err := os.OpenFile(cfg.Path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("access log open error: %w", err)
|
||||
}
|
||||
return NewAccessLogger(parent, &File{File: f}, cfg), nil
|
||||
}
|
||||
Reference in New Issue
Block a user