Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
add SaveToFile for context; remove Mode of tango
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Apr 10, 2015
1 parent 8f4289e commit 1424264
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tango [![Build Status](https://drone.io/github.com/lunny/tango/status.png)](http

Package tango is a micro-kernel & pluggable web framework for Go.

##### Current version: v0.4.2 [Version History](https://github.com/lunny/tango/releases)
##### Current version: v0.4.3 [Version History](https://github.com/lunny/tango/releases)

## Getting Started

Expand Down Expand Up @@ -88,6 +88,7 @@ There are already many [middlewares](https://github.com/tango-contrib) to simpli
- [events](https://github.com/tango-contrib/events) - [![Build Status](https://drone.io/github.com/tango-contrib/events/status.png)](https://drone.io/github.com/tango-contrib/events/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/events)](http://gocover.io/github.com/tango-contrib/events) Before and After
- [flash](https://github.com/tango-contrib/flash) - [![Build Status](https://drone.io/github.com/tango-contrib/flash/status.png)](https://drone.io/github.com/tango-contrib/flash/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/flash)](http://gocover.io/github.com/tango-contrib/flash) Share data between requests
- [debug](https://github.com/tango-contrib/debug) - [![Build Status](https://drone.io/github.com/tango-contrib/debug/status.png)](https://drone.io/github.com/tango-contrib/debug/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/debug)](http://gocover.io/github.com/tango-contrib/debug) show detail debug infomaton on log
- [basicauth](https://github.com/tango-contrib/basicauth) - [![Build Status](https://drone.io/github.com/tango-contrib/basicauth/status.png)](https://drone.io/github.com/tango-contrib/basicauth/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/basicauth)](http://gocover.io/github.com/tango-contrib/basicauth) basicauth middleware

## Getting Help

Expand Down
3 changes: 2 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tango [![Build Status](https://drone.io/github.com/lunny/tango/status.png)](http

Tango 是一个微内核易扩展的Go语言Web框架.

##### 当前版本: v0.4.2 [版本更新记录](https://github.com/lunny/tango/releases)
##### 当前版本: v0.4.3 [版本更新记录](https://github.com/lunny/tango/releases)

## 简介

Expand Down Expand Up @@ -88,6 +88,7 @@ func main() {
- [events](https://github.com/tango-contrib/events) - [![Build Status](https://drone.io/github.com/tango-contrib/events/status.png)](https://drone.io/github.com/tango-contrib/events/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/events)](http://gocover.io/github.com/tango-contrib/events) Before and After
- [flash](https://github.com/tango-contrib/flash) - [![Build Status](https://drone.io/github.com/tango-contrib/flash/status.png)](https://drone.io/github.com/tango-contrib/flash/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/flash)](http://gocover.io/github.com/tango-contrib/flash) Share data between requests
- [debug](https://github.com/tango-contrib/debug) - [![Build Status](https://drone.io/github.com/tango-contrib/debug/status.png)](https://drone.io/github.com/tango-contrib/debug/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/debug)](http://gocover.io/github.com/tango-contrib/debug) show detail debug infomaton on log
- [basicauth](https://github.com/tango-contrib/basicauth) - [![Build Status](https://drone.io/github.com/tango-contrib/basicauth/status.png)](https://drone.io/github.com/tango-contrib/basicauth/latest) [![](http://gocover.io/_badge/github.com/tango-contrib/basicauth)](http://gocover.io/github.com/tango-contrib/basicauth) basicauth middleware

## 获得帮助

Expand Down
16 changes: 16 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ func (ctx *Context) Download(fpath string) error {
return err
}

func (ctx *Context) SaveToFile(formName, savePath string) error {
file, _, err := ctx.Req().FormFile(formName)
if err != nil {
return err
}
defer file.Close()

f, err := os.OpenFile(savePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(f, file)
return err
}

func (ctx *Context) Redirect(url string, status ...int) {
s := http.StatusFound
if len(status) > 0 {
Expand Down
6 changes: 1 addition & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ type Logger interface {

func NewLogger(out io.Writer) Logger {
l := log.New(out, "[tango] ", log.Ldefault())
if Env == Dev {
l.SetOutputLevel(log.Ldebug)
} else {
l.SetOutputLevel(log.Linfo)
}
l.SetOutputLevel(log.Ldebug)
return l
}

Expand Down
2 changes: 1 addition & 1 deletion router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,4 @@ func TestRouter9(t *testing.T) {
expect(t, recorder.Code, http.StatusOK)
expect(t, buff.String(), "foobar")
refute(t, len(buff.String()), 0)
}
}
22 changes: 3 additions & 19 deletions tan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,12 @@ import (
"sync"
)

const (
Dev = iota
Prod
)

var (
Env = Dev

modes = []string{
"Dev",
"Product",
}
)

func Version() string {
return "0.4.2.0408"
return "0.4.3.0410"
}

type Tango struct {
Router
Mode int
handlers []Handler
logger Logger
ErrHandler Handler
Expand Down Expand Up @@ -98,7 +83,7 @@ func (t *Tango) Run(addrs ...string) {
addr = addrs[0]
}

t.logger.Info("listening on http", addr, modes[t.Mode])
t.logger.Info("listening on http", addr)

err := http.ListenAndServe(addr, t)
if err != nil {
Expand All @@ -114,7 +99,7 @@ func (t *Tango) RunTLS(certFile, keyFile string, addrs ...string) {
addr = addrs[0]
}

t.logger.Info("listening on https", addr, modes[t.Mode])
t.logger.Info("listening on https", addr)

err := http.ListenAndServeTLS(addr, certFile, keyFile, t)
if err != nil {
Expand Down Expand Up @@ -190,7 +175,6 @@ func (t *Tango) ServeHTTP(w http.ResponseWriter, req *http.Request) {
func NewWithLog(logger Logger, handlers ...Handler) *Tango {
tan := &Tango{
Router: NewRouter(),
Mode: Env,
logger: logger,
handlers: make([]Handler, 0),
ErrHandler: Errors(),
Expand Down

0 comments on commit 1424264

Please sign in to comment.