-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jason-ZW <zhenyang@rancher.com>
- Loading branch information
1 parent
30f2311
commit c553c99
Showing
86 changed files
with
11,498 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/rancher/apiserver/pkg/server" | ||
"github.com/rancher/apiserver/pkg/store/apiroot" | ||
"github.com/rancher/apiserver/pkg/types" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
serveCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "Run as daemon and serve HTTP/HTTPS request", | ||
} | ||
|
||
bindPort = "8080" | ||
bindAddress = "0.0.0.0" | ||
) | ||
|
||
func init() { | ||
serveCmd.Flags().StringVar(&bindPort, "bind-port", bindPort, "HTTP/HTTPS bind port") | ||
serveCmd.Flags().StringVar(&bindAddress, "bind-address", bindAddress, "HTTP/HTTPS bind address") | ||
} | ||
|
||
func ServeCommand() *cobra.Command { | ||
serveCmd.Run = func(cmd *cobra.Command, args []string) { | ||
s := server.DefaultAPIServer() | ||
|
||
apiroot.Register(s.Schemas, []string{"v1"}) | ||
|
||
router := mux.NewRouter() | ||
router.Handle("/{prefix}/{type}", s) | ||
router.Handle("/{prefix}/{type}/{id}", s) | ||
|
||
router.NotFoundHandler = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { | ||
s.Handle(&types.APIRequest{ | ||
Request: r, | ||
Response: rw, | ||
Type: "apiRoot", | ||
URLPrefix: "v1", | ||
}) | ||
}) | ||
|
||
logrus.Infof("run as daemon, listening on %s:%s", bindAddress, bindPort) | ||
logrus.Fatal(http.ListenAndServe(fmt.Sprintf("%s:%s", bindAddress, bindPort), router)) | ||
} | ||
|
||
return serveCmd | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.