mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-08 00:50:28 +08:00
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
// Copyright 2020 The casbin Authors. All Rights Reserved.
|
|
//
|
|
// 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 main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"time"
|
|
|
|
"github.com/casdoor/casdoor/internal/config"
|
|
"github.com/casdoor/casdoor/internal/handler"
|
|
"github.com/casdoor/casdoor/internal/store"
|
|
"github.com/casdoor/casdoor/internal/store/shared"
|
|
)
|
|
|
|
func main() {
|
|
cfg, err := config.NewConfig()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
db, err := shared.NewDB(cfg)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
userStore := store.NewUserStore(db)
|
|
applicationStore := store.NewApplicationStore(db)
|
|
|
|
srv := &http.Server{
|
|
Addr: cfg.HTTPPort,
|
|
Handler: handler.New(userStore, applicationStore),
|
|
}
|
|
|
|
go func() {
|
|
log.Printf("listen and serve on %s", srv.Addr)
|
|
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
log.Fatalf("listen: %s\n", err)
|
|
}
|
|
}()
|
|
|
|
quit := make(chan os.Signal)
|
|
signal.Notify(quit, os.Interrupt)
|
|
<-quit
|
|
log.Println("Shutdown Server ...")
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
if err := srv.Shutdown(ctx); err != nil {
|
|
log.Fatal("Server Shutdown:", err)
|
|
}
|
|
log.Println("Server exiting")
|
|
}
|