-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bo Du
committed
Nov 19, 2018
1 parent
f10bfa5
commit c656215
Showing
6 changed files
with
126 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,32 @@ | ||
package database | ||
|
||
type Options struct{} | ||
|
||
// Database exposes methods to write and query data. | ||
type Database interface { | ||
WriteBatch([][]byte) error | ||
Write([]byte) error | ||
// TODO: Implement query package and then method. | ||
//Query() | ||
} | ||
|
||
// DB implements the Database interface. | ||
type DB struct { | ||
opts Options | ||
} | ||
|
||
func New(opts Options) *DB { | ||
return &DB{ | ||
opts: opts, | ||
} | ||
} | ||
|
||
// WriteBatch persists multiple events. | ||
func (d *DB) WriteBatch(events [][]byte) error { | ||
return nil | ||
} | ||
|
||
// Write persists a single event. | ||
func (d *DB) Write(event []byte) error { | ||
return d.WriteBatch([][]byte{event}) | ||
} |
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,12 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/xichen2020/eventdb/services/eventdb/database" | ||
"github.com/xichen2020/eventdb/services/eventdb/server" | ||
) | ||
|
||
// Config holds all eventdb config options. | ||
type Config struct { | ||
Database database.Options `yaml"database"` | ||
Server server.Options `yaml:"server"` | ||
} |
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 |
---|---|---|
@@ -1,7 +1,40 @@ | ||
package main | ||
|
||
import "fmt" | ||
import ( | ||
"flag" | ||
|
||
"github.com/m3db/m3x/config" | ||
"github.com/m3db/m3x/log" | ||
"github.com/xichen2020/eventdb/services/eventdb/database" | ||
"github.com/xichen2020/eventdb/services/eventdb/server" | ||
) | ||
|
||
var ( | ||
configFilePath string | ||
logger = log.SimpleLogger | ||
) | ||
|
||
func main() { | ||
fmt.Println("hello world!") | ||
// Parse command line args. | ||
flag.Parse() | ||
|
||
var cfg Config | ||
if err := config.LoadFile(&cfg, configFilePath, config.Options{}); err != nil { | ||
logger.Fatalf("logstore load config error: %v", err) | ||
} | ||
|
||
// Instantiate DB. | ||
db := database.New(cfg.Database) | ||
|
||
// Spin up server. | ||
s := server.New(cfg.Server, db) | ||
go func() { | ||
if err := s.Serve(); err != nil { | ||
logger.Fatalf("Failed to serve HTTP endpoints: %v", err) | ||
} | ||
}() | ||
} | ||
|
||
func init() { | ||
flag.StringVar(&configFilePath, "config", "eventdb.yaml", "path to the eventdb config file") | ||
} |
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,33 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/xichen2020/eventdb/services/eventdb/database" | ||
) | ||
|
||
// Options for a server. | ||
type Options struct { | ||
Port int | ||
} | ||
|
||
// Server exposes http endpoints that handle reads and writes. | ||
// Uses the default servemux under the hood. | ||
type Server struct { | ||
opts Options | ||
db database.Database | ||
} | ||
|
||
// New returns a new server instance. | ||
func New(opts Options, db database.Database) *Server { | ||
return &Server{ | ||
opts: opts, | ||
db: db, | ||
} | ||
} | ||
|
||
// Serve runs the server. | ||
func (s *Server) Serve() error { | ||
return http.ListenAndServe(fmt.Sprintf(":%d", s.opts.Port), nil) | ||
} |