代码拉取完成,页面将自动刷新
/*
Copyright 2020 KubeSphere Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package options
import (
"crypto/tls"
"gitee.com/websample/webserver/pkg/apiserver"
"net/http"
"fmt"
flag "github.com/spf13/pflag"
)
type ServerRunOptions struct {
// server bind address
BindAddress string
// insecure port number
InsecurePort int
// secure port number
SecurePort int
// tls cert file
TlsCertFile string
// tls private key file
TlsPrivateKey string
//
DebugMode bool
}
// NewServerRunOptions 初始化server 启动参数
func NewServerRunOptions() *ServerRunOptions {
s := ServerRunOptions{
BindAddress: "0.0.0.0",
InsecurePort: 9090,
SecurePort: 0,
TlsCertFile: "",
TlsPrivateKey: "",
}
return &s
}
// AddFlags 添加程序入参
func (s *ServerRunOptions) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&s.BindAddress, "bind-address", s.BindAddress, "server bind address")
fs.IntVar(&s.InsecurePort, "insecure-port", s.InsecurePort, "insecure port number")
fs.IntVar(&s.SecurePort, "secure-port", s.SecurePort, "secure port number")
fs.StringVar(&s.TlsCertFile, "tls-cert-file", s.TlsCertFile, "tls cert file")
fs.StringVar(&s.TlsPrivateKey, "tls-private-key", s.TlsPrivateKey, "tls private key")
}
// NewAPIServer creates an APIServer instance using given options
func (s *ServerRunOptions) NewAPIServer(stopCh <-chan struct{}) (*apiserver.APIServer, error) {
apiServer := &apiserver.APIServer{}
server := &http.Server{
Addr: fmt.Sprintf(":%d", s.InsecurePort),
}
if s.SecurePort != 0 {
certificate, err := tls.LoadX509KeyPair(s.TlsCertFile, s.TlsPrivateKey)
if err != nil {
return nil, err
}
server.TLSConfig.Certificates = []tls.Certificate{certificate}
}
apiServer.Server = server
return apiServer, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。