コード例 #1
0
ファイル: volumeinfo_ws.go プロジェクト: Norwae/what-i-read
func normalize(call *Call, info *data.BookMetaData) {
	var isbn isbn13.ISBN13
	var err error
	if isbn, err = isbn13.New(info.ISBN); err == nil {
		var base *data.BookMetaData
		if base, err = persistence.LookupISBN(call.Context, call.DetermineCountry(), isbn); err == nil {
			info.Volume.Images = base.Volume.Images
			return
		} else {
			info.Volume.Images = data.ImageLinks{}
		}
	} else {
		call.Context.Errorf("Could not normalize data for %s: %s", info.ISBN, err.Error())
	}
}
コード例 #2
0
ファイル: volumeinfo_ws.go プロジェクト: Norwae/what-i-read
func serveVolumeSingle(call *Call) (interface{}, error) {
	isbn, err := isbn13.New(call.Request.URL.Path[9:])
	var book *data.BookMetaData

	if err == nil {
		switch call.Request.Method {
		case "GET":
			book, err = compositeISBNLookup(call.Context, call.DetermineCountry(), isbn)
		case "PUT":
			book, err = putVolumeSingle(call, isbn)
		case "DELETE":
			book, err = deleteVolumeSingle(call, isbn)
		default:
			call.StatusCode = http.StatusMethodNotAllowed
			call.Response.Header().Add("Allow", "GET, PUT, DELETE")
			err = errors.New("Unsupported operation. Only GET, PUT and DELETE methods are allowed")
		}
	} else {
		call.StatusCode = http.StatusNotFound
	}

	return book, err
}