Skip to content

Commit

Permalink
Use arrow functions (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Sep 17, 2018
1 parent 98201be commit ba49ef3
Show file tree
Hide file tree
Showing 11 changed files with 541 additions and 610 deletions.
6 changes: 3 additions & 3 deletions samples/fluent.js
Expand Up @@ -18,7 +18,7 @@
const express = require('express');
const app = express();

app.get('*', function(req, res, next) {
app.get('*', (req, res, next) => {
return next('oops');
});

Expand All @@ -29,7 +29,7 @@ const structuredLogger = require('fluent-logger').createFluentSender('myapp', {
timeout: 3.0,
});

const report = function(err, req) {
const report = (err, req) => {
const payload = {
serviceContext: {
service: 'myapp',
Expand All @@ -51,7 +51,7 @@ const report = function(err, req) {

// Handle errors (the following uses the Express framework)
// eslint-disable-next-line no-unused-vars
app.use(function(err, req, res, next) {
app.use((err, req, res, next) => {
report(err, req);
res.status(500).send(err.response || 'Something broke!');
});
Expand Down
4 changes: 2 additions & 2 deletions src/entry.js
Expand Up @@ -64,7 +64,7 @@ const eventId = new EventId();
* delegate: 'my_username'
* });
*
* syslog.alert(entry, function(err, apiResponse) {
* syslog.alert(entry, (err, apiResponse) => {
* if (!err) {
* // Log entry inserted successfully.
* }
Expand All @@ -74,7 +74,7 @@ const eventId = new EventId();
* // You will also receive `Entry` objects when using
* // Logging#getEntries() and Log#getEntries().
* //-
* logging.getEntries(function(err, entries) {
* logging.getEntries((err, entries) => {
* if (!err) {
* // entries[0].data = The data value from the log entry.
* }
Expand Down
50 changes: 25 additions & 25 deletions src/index.js
Expand Up @@ -202,7 +202,7 @@ class Logging {
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* logging.createSink('new-sink-name', config).then(function(data) {
* logging.createSink('new-sink-name', config).then(data => {
* const sink = data[0];
* const apiResponse = data[1];
* });
Expand Down Expand Up @@ -244,7 +244,7 @@ class Logging {
reqOpts: reqOpts,
gaxOpts: config.gaxOptions,
},
function(err, resp) {
(err, resp) => {
if (err) {
callback(err, null, resp);
return;
Expand Down Expand Up @@ -350,7 +350,7 @@ class Logging {
* const {Logging} = require('@google-cloud/logging');
* const logging = new Logging();
*
* logging.getEntries(function(err, entries) {
* logging.getEntries((err, entries) => {
* // `entries` is an array of Stackdriver Logging entry objects.
* // See the `data` property to read the data from the entry.
* });
Expand All @@ -373,7 +373,7 @@ class Logging {
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* logging.getEntries().then(function(data) {
* logging.getEntries().then(data => {
* const entries = data[0];
* });
*
Expand Down Expand Up @@ -441,7 +441,7 @@ class Logging {
*
* logging.getEntriesStream()
* .on('error', console.error)
* .on('data', function(entry) {
* .on('data', entry => {
* // `entry` is a Stackdriver Logging entry object.
* // See the `data` property to read the data from the entry.
* })
Expand All @@ -463,15 +463,15 @@ class Logging {
options = options || {};
let requestStream;
const userStream = streamEvents(pumpify.obj());
userStream.abort = function() {
userStream.abort = () => {
if (requestStream) {
requestStream.abort();
}
};
const toEntryStream = through.obj(function(entry, _, next) {
const toEntryStream = through.obj((entry, _, next) => {
next(null, Entry.fromApiResponse_(entry));
});
userStream.once('reading', function() {
userStream.once('reading', () => {
const reqOpts = extend(
{
orderBy: 'timestamp desc',
Expand Down Expand Up @@ -537,14 +537,14 @@ class Logging {
* const {Logging} = require('@google-cloud/logging');
* const logging = new Logging();
*
* logging.getSinks(function(err, sinks) {
* logging.getSinks((err, sinks) => {
* // sinks is an array of Sink objects.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* logging.getSinks().then(function(data) {
* logging.getSinks().then(data => {
* const sinks = data[0];
* });
*
Expand Down Expand Up @@ -579,7 +579,7 @@ class Logging {
function() {
const sinks = arguments[1];
if (sinks) {
arguments[1] = sinks.map(function(sink) {
arguments[1] = sinks.map(sink => {
const sinkInstance = self.sink(sink.name);
sinkInstance.metadata = sink;
return sinkInstance;
Expand All @@ -605,7 +605,7 @@ class Logging {
*
* logging.getSinksStream()
* .on('error', console.error)
* .on('data', function(sink) {
* .on('data', sink => {
* // `sink` is a Sink object.
* })
* .on('end', function() {
Expand All @@ -626,17 +626,17 @@ class Logging {
options = options || {};
let requestStream;
const userStream = streamEvents(pumpify.obj());
userStream.abort = function() {
userStream.abort = () => {
if (requestStream) {
requestStream.abort();
}
};
const toSinkStream = through.obj(function(sink, _, next) {
const toSinkStream = through.obj((sink, _, next) => {
const sinkInstance = self.sink(sink.name);
sinkInstance.metadata = sink;
next(null, sinkInstance);
});
userStream.once('reading', function() {
userStream.once('reading', () => {
const reqOpts = extend({}, options, {
parent: 'projects/' + self.projectId,
});
Expand Down Expand Up @@ -711,7 +711,7 @@ class Logging {
let stream;
if (isStreamMode) {
stream = streamEvents(through.obj());
stream.abort = function() {
stream.abort = () => {
if (gaxStream && gaxStream.cancel) {
gaxStream.cancel();
}
Expand All @@ -721,7 +721,7 @@ class Logging {
makeRequestCallback();
}
function prepareGaxRequest(callback) {
self.auth.getProjectId(function(err, projectId) {
self.auth.getProjectId((err, projectId) => {
if (err) {
callback(err);
return;
Expand All @@ -747,7 +747,7 @@ class Logging {
if (global.GCLOUD_SANDBOX_ENV) {
return;
}
prepareGaxRequest(function(err, requestFn) {
prepareGaxRequest((err, requestFn) => {
if (err) {
callback(err);
return;
Expand All @@ -759,14 +759,14 @@ class Logging {
if (global.GCLOUD_SANDBOX_ENV) {
return through.obj();
}
prepareGaxRequest(function(err, requestFn) {
prepareGaxRequest((err, requestFn) => {
if (err) {
stream.destroy(err);
return;
}
gaxStream = requestFn();
gaxStream
.on('error', function(err) {
.on('error', err => {
stream.destroy(err);
})
.pipe(stream);
Expand All @@ -786,7 +786,7 @@ class Logging {
setAclForBucket_(name, config, callback) {
const self = this;
const bucket = config.destination;
bucket.acl.owners.addGroup('cloud-logs@google.com', function(err, apiResp) {
bucket.acl.owners.addGroup('cloud-logs@google.com', (err, apiResp) => {
if (err) {
callback(err, null, apiResp);
return;
Expand All @@ -808,7 +808,7 @@ class Logging {
setAclForDataset_(name, config, callback) {
const self = this;
const dataset = config.destination;
dataset.getMetadata(function(err, metadata, apiResp) {
dataset.getMetadata((err, metadata, apiResp) => {
if (err) {
callback(err, null, apiResp);
return;
Expand All @@ -822,7 +822,7 @@ class Logging {
{
access: access,
},
function(err, apiResp) {
(err, apiResp) => {
if (err) {
callback(err, null, apiResp);
return;
Expand All @@ -848,7 +848,7 @@ class Logging {
setAclForTopic_(name, config, callback) {
const self = this;
const topic = config.destination;
topic.iam.getPolicy(function(err, policy, apiResp) {
topic.iam.getPolicy((err, policy, apiResp) => {
if (err) {
callback(err, null, apiResp);
return;
Expand All @@ -858,7 +858,7 @@ class Logging {
role: 'roles/pubsub.publisher',
members: ['serviceAccount:cloud-logs@system.gserviceaccount.com'],
});
topic.iam.setPolicy(policy, function(err, policy, apiResp) {
topic.iam.setPolicy(policy, (err, policy, apiResp) => {
if (err) {
callback(err, null, apiResp);
return;
Expand Down

0 comments on commit ba49ef3

Please sign in to comment.