-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Improve data ownership interface
- Loading branch information
1 parent
a2b75a1
commit 5d639ab
Showing
12 changed files
with
189 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package gluon | ||
|
||
import ( | ||
"crypto/tls" | ||
"io" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/ProtonMail/gluon/events" | ||
"github.com/ProtonMail/gluon/internal" | ||
"github.com/ProtonMail/gluon/internal/backend" | ||
"github.com/ProtonMail/gluon/internal/session" | ||
"github.com/ProtonMail/gluon/profiling" | ||
"github.com/ProtonMail/gluon/store" | ||
) | ||
|
||
type serverBuilder struct { | ||
dir string | ||
delim string | ||
tlsConfig *tls.Config | ||
inLogger io.Writer | ||
outLogger io.Writer | ||
versionInfo internal.VersionInfo | ||
cmdExecProfBuilder profiling.CmdProfilerBuilder | ||
storeBuilder store.Builder | ||
} | ||
|
||
func newBuilder() (*serverBuilder, error) { | ||
return &serverBuilder{ | ||
delim: "/", | ||
cmdExecProfBuilder: &profiling.NullCmdExecProfilerBuilder{}, | ||
storeBuilder: &store.OnDiskStoreBuilder{}, | ||
}, nil | ||
} | ||
|
||
func (builder *serverBuilder) build() (*Server, error) { | ||
if builder.dir == "" { | ||
dir, err := os.MkdirTemp("", "gluon-*") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
builder.dir = dir | ||
} | ||
|
||
if err := os.MkdirAll(builder.dir, 0o700); err != nil { | ||
return nil, err | ||
} | ||
|
||
backend, err := backend.New(filepath.Join(builder.dir, "backend"), builder.storeBuilder, builder.delim) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Server{ | ||
dir: builder.dir, | ||
backend: backend, | ||
listeners: make(map[net.Listener]struct{}), | ||
sessions: make(map[int]*session.Session), | ||
inLogger: builder.inLogger, | ||
outLogger: builder.outLogger, | ||
tlsConfig: builder.tlsConfig, | ||
watchers: make(map[chan events.Event]struct{}), | ||
storeBuilder: builder.storeBuilder, | ||
cmdExecProfBuilder: builder.cmdExecProfBuilder, | ||
versionInfo: builder.versionInfo, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.