mirror of
https://github.com/bolucat/Archive.git
synced 2025-09-26 20:21:35 +08:00
Update On Thu Sep 25 20:42:16 CEST 2025
This commit is contained in:
@@ -75,16 +75,16 @@ func (mc *mieruClient) Store(config *ClientConfig) error {
|
||||
mc.mu.Lock()
|
||||
defer mc.mu.Unlock()
|
||||
if config == nil {
|
||||
return fmt.Errorf("%w: client config is nil", ErrInvalidConfigConfig)
|
||||
return fmt.Errorf("%w: client config is nil", ErrInvalidClientConfig)
|
||||
}
|
||||
if config.Profile == nil {
|
||||
return fmt.Errorf("%w: client config profile is nil", ErrInvalidConfigConfig)
|
||||
return fmt.Errorf("%w: client config profile is nil", ErrInvalidClientConfig)
|
||||
}
|
||||
if mc.running {
|
||||
return ErrStoreClientConfigAfterStart
|
||||
}
|
||||
if err := appctlcommon.ValidateClientConfigSingleProfile(config.Profile); err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrInvalidConfigConfig, err.Error())
|
||||
return fmt.Errorf("%w: %s", ErrInvalidClientConfig, err.Error())
|
||||
}
|
||||
mc.config = config
|
||||
return nil
|
@@ -26,12 +26,12 @@ import (
|
||||
|
||||
var (
|
||||
ErrNoClientConfig = errors.New("no client config")
|
||||
ErrInvalidConfigConfig = errors.New("invalid client config")
|
||||
ErrInvalidClientConfig = errors.New("invalid client config")
|
||||
ErrClientIsNotRunning = errors.New("client is not running")
|
||||
ErrStoreClientConfigAfterStart = errors.New("can't store client config after start")
|
||||
)
|
||||
|
||||
// Client contains methods supported by a mieru client.
|
||||
// Client contains methods supported by a proxy client.
|
||||
type Client interface {
|
||||
ClientConfigurationService
|
||||
ClientLifecycleService
|
||||
|
18
mieru/apis/server/doc.go
Normal file
18
mieru/apis/server/doc.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (C) 2025 mieru authors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
// Package server provides mieru server APIs for third party applications
|
||||
// to integrate mieru protocol.
|
||||
package server
|
73
mieru/apis/server/interface.go
Normal file
73
mieru/apis/server/interface.go
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2025 mieru authors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/enfein/mieru/v3/pkg/appctl/appctlpb"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoServerConfig = errors.New("no server config")
|
||||
ErrInvalidServerConfig = errors.New("invalid server config")
|
||||
ErrServerIsNotRunning = errors.New("server is not running")
|
||||
ErrStoreServerConfigAfterStart = errors.New("can't store server config after start")
|
||||
)
|
||||
|
||||
// Server contains methods supported by a proxy server.
|
||||
type Server interface {
|
||||
ServerConfigurationService
|
||||
ServerLifecycleService
|
||||
ServerNetworkService
|
||||
}
|
||||
|
||||
// ServerConfigurationService contains methods to manage proxy server configuration.
|
||||
type ServerConfigurationService interface {
|
||||
// Load returns the server config.
|
||||
// It returns ErrNoServerConfig if server config is never stored.
|
||||
Load() (*ServerConfig, error)
|
||||
|
||||
// Store saves the server config.
|
||||
// It returns wrapped ErrInvalidServerConfig error
|
||||
// if the provided server config is invalid.
|
||||
// It returns ErrStoreServerConfigAfterStart error
|
||||
// if it is called after start.
|
||||
Store(*ServerConfig) error
|
||||
}
|
||||
|
||||
// ServerLifecycleService contains methods to manage proxy server lifecycle.
|
||||
type ServerLifecycleService interface {
|
||||
// Start activates the server with the stored configuration.
|
||||
// Calling Start function more than once has undefined behavior.
|
||||
Start() error
|
||||
|
||||
// Stop deactivates the server.
|
||||
// Established network connections are NOT terminated.
|
||||
// After stop, the server can't be reused.
|
||||
Stop() error
|
||||
|
||||
// IsRunning returns true if the server has been started
|
||||
// and has not been stopped.
|
||||
IsRunning() bool
|
||||
}
|
||||
|
||||
type ServerNetworkService interface{}
|
||||
|
||||
// ServerConfig stores proxy server configuration.
|
||||
type ServerConfig struct {
|
||||
Config *appctlpb.ServerConfig
|
||||
}
|
Reference in New Issue
Block a user