One place for hosting & domains

      July 2019

      Understanding Arrays in Go


      An array in Go is an ordered sequence of elements that has its capacity defined at creation time. Once an array has allocated its size, the size can no longer be changed. Because the size of an array is static, the data structure only needs to allocate memory once, as opposed to a variable length data structure that must dynamically allocate memory so that it can become larger or smaller in the future.

      Although the fixed length of arrays can make them somewhat rigid to work with, the one-time memory allocation can increase the speed and performance of your program. Because of this, developers typically use arrays when optimizing programs. In Go, slices are the variable length version of arrays. Slices provide more flexibility and constitute what you would think of as arrays in other languages.

      In this article, you will learn how to declare an array, how to call individual elements using indexing, how to slice the array into smaller sets, and the difference between an array and a slice in Go.

      Defining an Array

      Arrays are defined by declaring the size of the array in brackets [ ], followed by the data type of the elements. An array in Go must have all its elements be the same data type. After the data type, you can declare the individual values of the array elements in curly brackets { }.

      The following is the general schema for declaring an array:


      Note: It is important to remember that every declaration of a new array creates a distinct type. So, although [2]int and [3]int both have integer elements, their differing capacities make their data types incompatible.

      If you do not declare the values of the array’s elements, the default is zero-valued, which means that the array elements of the array will be empty. For integers, this is represented by 0, and for strings this is represented by an empty string.

      For example, the following array numbers has three integer elements that do not yet have a value:

      var numbers [3]int

      If you printed numbers, you would recieve the following output:


      [0 0 0]

      If you would like to assign the values of the elements when you create the array, place the values in curly brackets. An array of strings with set values looks like this:

      [4]string{"blue coral", "staghorn coral", "pillar coral", "elkhorn coral"}

      You can store an array in a variable and print it out:

      coral := [4]string{"blue coral", "staghorn coral", "pillar coral", "elkhorn coral"}

      Running a program with the preceding lines would give you the following output:


      [blue coral staghorn coral pillar coral elkhorn coral]

      Notice that there is no delineation between the elements in the array when it is printed, making it difficult to tell where one element ends and another begins. Because of this, it is sometimes helpful to use the fmt.Printf function instead, which can format strings before printing them to the screen. Provide the %q verb with this command to instruct the function to put quotation marks around the values:

      fmt.Printf("%qn", coral)

      This will result in the following:


      ["blue coral" "staghorn coral" "pillar coral" "elkhorn coral"]

      Now each item is quoted. The n verb instructs to the formatter to add a line return at the end.

      With a general idea of how to declare arrays and what they consist of, you can now move on to learning how to specify elements in an array with indexes.

      Indexing Arrays

      Each element in an array can be called individually through indexing. Each element corresponds to an index number, which is an int value starting from the index number 0 and counting up.

      For the coral array from the earlier example, the index breakdown looks like this:

      “blue coral” “staghorn coral” “pillar coral” “elkhorn coral”
      0 1 2 3

      The first element, the string 'blue coral', starts at index 0, and the list ends at index 3 with the item 'elkhorn coral'.

      You can call a discrete element of the array by referring to its index number in brackets after the variable in which the array is stored:


      This will print the following:


      pillar coral

      The index numbers for this array range from 03, so to call any of the elements individually and assign them a value, you could refer to the index numbers like this:

      coral[0] = "blue coral"
      coral[1] = "staghorn coral"
      coral[2] = "pillar coral"
      coral[3] = "elkhorn coral"

      If you call the array coral with an index number greater than 3, it will be out of range, and Go will consider the action invalid:



      invalid array index 22 (out of bounds for 4-element array)

      When indexing an array, you must always use a positive number. Unlike some languages that let you index backwards with a negative number, doing that in Go will result in an error:



      invalid array index -1 (index must be non-negative)

      Now that you know how to work with individual elements in an array, you can learn how to slice arrays to select a range of elements.

      Slicing Arrays

      By using index numbers to determine beginning and endpoints, you can call a subsection of the values within an array. This is called slicing the array. You can do this by creating a range of index numbers separated by a colon, in the form of [first_index:second_index].

      Let’s say you would like to just print the middle items of coral, without the first and last element. You can do this by creating a slice starting at index 1 and ending just before index 3:


      Running a program with this line would yield the following:


      [staghorn coral pillar coral]

      When creating a slice, as in [1:3], the first number is where the slice starts (inclusive), and the second number is the sum of the first number and the total number of elements you would like to retrieve:

      array[starting_index : (starting_index + length_of_slice)]

      In this instance, you called the second element (or index 1) as the starting point, and called two elements in total. This is how the calculation would look:

      array[1 : (1 + 2)]

      Which is how you arrived at this notation:


      If you want to set the beginning or end of the array as a starting or end point of the slice, you can omit one of the numbers in the array[first_index:second_index] syntax. For example, if you want to print the first three items of the array coral — which would be "blue coral", "staghorn coral", and "pillar coral" — you can do so by typing:


      This will print:


      [blue coral staghorn coral pillar coral]

      This printed the beginning of the array, stopping right before index 3.

      To include all the items at the end of an array, you would reverse the syntax:


      This would give the following:


      [staghorn coral pillar coral elkhorn coral]

      This section discussed calling individual parts of an array by slicing out subsections. Next, you’ll learn a specific function that Go uses for arrays: len().

      Array Functions

      In Go, len() is a built-in function made to help you work with arrays. Like with strings, you can calculate the length of an array by using len() and passing in the array as a parameter.

      For example, to find how many elements are in the coral array, you would use:


      If you print out the length for the array coral, you’ll receive the following output:



      This gives the length of the array 4 in the int data type, which is correct because the array coral has four items:

      coral := [4]string{"blue coral", "staghorn coral", "pillar coral", "elkhorn coral"}

      If you create an array of integers with more elements, you could use the len() function on this as well:

      numbers := [13]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}

      This would result in the following output:



      Although these example arrays have relatively few items, the len() function is especially useful when determining how many elements are in very large arrays.

      Now that you know how to use len() to output the length of arrays, you can learn how arrays differ from another common data structure: slices.

      How Arrays Differ from Slices

      As mentioned before, the primary way in which arrays are different from slices is that the size of an array cannot be modified. This means that while you can change the values of elements in an array, you can’t make the array larger or smaller after it has been defined. A slice, on the other hand, can alter its length.

      Let’s consider your coral array:

      coral := [4]string{"blue coral", "staghorn coral", "pillar coral", "elkhorn coral"}

      Say you want to add the item "black coral" to this array. If you try to use the append() function with the array by typing:

      coral = append(coral, "black coral")

      You will receive an error as your output:


      first argument to append must be slice; have [4]string

      If you create an array and decide that you need it to have a variable length, you can convert it to a slice. To convert an array to a slice, use the slicing process you learned in the Slicing Arrays step of this tutorial, except this time select the entire slice by omitting both of the index numbers that would determine the endpoints:


      Keep in mind that you can’t convert the variable coral to a slice itself, since once a variable is defined in Go, its type can’t be changed. To work around this, you can copy the entire contents of the array into a new variable as a slice:

      coralSlice := coral[:]

      If you printed coralSlice, you would receive the following output:


      [blue coral staghorn coral pillar coral elkhorn coral]

      Now, try to use append() with the newly converted slice:

      newSlice := append(coralSlice, "black coral")
      fmt.Printf("%qn", newSlice)

      This will output the slice with the added element:


      ["blue coral" "staghorn coral" "pillar coral" "elkhorn coral" "black coral"]


      In this tutorial, you learned that the array data type is a sequenced data type with a fixed length, which makes it faster for Go to process at the cost of flexibility. Arrays also can help with communication on a team of developers: When others collaborate with you on your code, your use of arrays will convey to them that you don’t intend for their lengths to be changed.

      With this data type in your tool box, you can now go more in-depth learning the variable length version of this structure: slices.

      Source link

      How to Write Meta Descriptions That Get Clicks (5 Key Tips)

      Search engines can make or break websites. Getting your site to show up on Search Engine Results Pages (SERPs) often isn’t enough. You also have to get people’s attention, so they’ll click on your links over the hundreds of other options.

      At their core, meta descriptions give potential visitors an overview of what kind of content they can expect. They tend to be just a few lines long, so small differences in the way you write your meta descriptions can be enough to boost your click-through rate significantly.

      In this article, we’re going to talk about what meta descriptions are, why they’re necessary, and what elements they should include. Then we’ll walk you through five tips to ensure that your meta descriptions hit home every time. Let’s get to it!

      Shared Hosting That Powers Your Purpose

      We make sure your website is fast, secure and always up so your visitors trust you. Plans start at $2.59/mo.

      An Introduction to Meta Descriptions

      Meta descriptions are the snippets of text you see underneath the title within SERPs, as in the example below.

      Two examples of meta descriptions.

      The main goal of a good meta description is to give you an idea of what the page is all about. Naturally, titles also play a vital role here, but there’s only so much information you can fit into a single headline.

      Meta descriptions provide you with up to a couple of sentences to expand on your page’s content. You can either write them yourself or have search engines generate them automatically based on each user’s search query.

      As convenient as having search engines do the work for you sounds, however, we strongly recommend that you write your own meta descriptions. That way, you get full control over what shows up on the SERPs and on social media sites while also increasing your chances of engaging users.

      Let’s take a look at some meta description examples for a specific line of shoes. You can tell the meta description below was generated automatically, and it doesn’t give you much to go on.

      An example of an unoptimized meta description.

      Here’s another result for the same product search, this one using a stronger meta description.

      An example of an optimized meta description.

      It’s important to understand that meta descriptions only give you a limited number of characters to play with. On desktops, that can be up to 158 characters, whereas mobile users will only see 120 of them. Roughly speaking, that means you get about two lines of text.

      Why Meta Descriptions Are Important

      Search Engine Optimization (SEO) is all about competition. You compete against every other site that appears within the results pages for a given search, each hoping to get the lion’s share of the clicks.

      When it comes to the SERPs, several factors determine how many views your links get, including:

      • The title you use
      • Whether it’s a rich snippet or not
      • If it appears within an answer box
      • The position of your pages
      • Your meta descriptions

      Out of all those factors, you get full control over three of them: your title, schema markup, and meta descriptions. It’s only logical that you should optimize those elements as much as possible.

      If you take another look at the previous section, you’ll notice just how much of a difference a good meta description can make. Letting search engines generate yours will often result in descriptions that look like gibberish.

      What to Include in a Meta Description

      Two lines of text aren’t much, but more often than not, it’s enough to cover a few key elements. Most often, this should include:

      • What your page is about
      • How it can benefit the reader

      If a meta description is too vague, then you’re not selling users on the idea of visiting your website. You’ll still get clicks, of course, but not as many as you might have otherwise.

      Let’s say, for example, that you wanted to write a meta description for this article. Here’s a not-so-good example:

      Have you ever wondered what meta descriptions are? Wonder no more, because we’ll tell you everything you need to know.

      While it hits on the article’s primary topic, it doesn’t do a good job of previewing the page’s actual content. Now let’s give it another go, keeping in mind the fundamental elements we want to include:

      Meta descriptions are key to any site’s SEO. In this article, we’ll break down why and help you optimize your own descriptions. Read on to find out more!

      This is short and to the point, and we even had enough characters left over to include a simple Call to Action (CTA). It may not win any literary awards, but it will get the job done.

      How to Write Meta Descriptions That Get Clicks (5 Key Tips)

      At this point, you know the basics of what a meta description should include. However, if you want your descriptions to really hit home, here are five tips to help you optimize them further.

      1. Use Relevant Keywords

      If you’re reading this, you’re probably familiar with the concept of keywords. Ideally, you’ll use them organically throughout all of your content, and that includes metadata such as your descriptions.

      Let’s say, for example, that you’re writing a recipe and you want to optimize it for the search term “how to cook a healthy lasagna.” That’s an easy to term to work into a meta description:

      Learning how to cook a healthy lasagna is easier than you might imagine. Let’s go over a recipe you can cook in under two hours!

      Including keywords within your meta descriptions is a smart SEO practice. It gives search engines a better idea of what your content is all about. However, as always, make sure to work those meta keywords in organically. That means not stuffing your descriptions full of keywords; make your description still reads like something a human (not a bot) would write.

      2. Don’t Obsess Over the Character Count

      So far, most of the examples we’ve shown you have come in well under the maximum character count for the major search engines. You want to get some mileage out of your meta descriptions, but in practice, obsessing over the character count isn’t as serious as you might think.

      To build on our earlier example of a healthy lasagna recipe, you could easily expand on its description to cover more information:

      Learning how to cook a healthy lasagna is easier than you might imagine. For this recipe, we’re substituting meat with eggplants, which means it will cook faster and feed up to four people.

      That example goes over the character limit for both desktop and mobile meta descriptions in Google. In practice, it would get cut off and look something like this:

      Learning how to cook a healthy lasagna is easier than you might imagine. For this recipe, we’re substituting meat with eggplants, which means it will cook …

      That snippet still provides plenty of information, so you don’t necessarily need to change it. What matters is that you include the essential details early on, so whatever does get cut off is just supplementary information.

      3. Optimize for Rich Snippets

      Most search results look pretty dull — a sea of titles, meta descriptions, and URLs. However, in some cases, your results will look a bit more lively.

      Three examples of carbonara recipes with rich snippets.

      Those are examples of rich snippets. To create them, you add structured data markup to your pages, providing more information on what their content includes. Search engines can recognize that information and structure your results accordingly.

      This practice offers two key benefits:

      1. Your pages will look more engaging within the SERPs.
      2. You get to add a ton of extra information to your results, without needing to count characters.

      For a real example, let’s take a look at the results for “how to cook a healthy lasagna.”

      Two healthy lasagna recipes with rich snippets.

      Two of the top results are featured snippets. Without even clicking on them, you can see an image, cooking time, rating, and even the number of calories in the recipe.

      Keep in mind that not all types of content lend themselves well to rich snippets. However, they’re pretty easy to implement, once you know how to add the right structured data markup to your pages.

      4. Avoid Duplicates

      When it comes to meta descriptions, there are two kinds of potential duplicates. It’s good practice to avoid both of them:

      1. Mimicking other sites’ descriptions
      2. Having several of your pages use the same description

      Overall, duplicate content is almost always bad news when it comes to SEO. Moreover, it can hurt your click-through rate if you have several pages competing for the same search terms.

      For practical purposes, there’s no reason all of your pages shouldn’t have unique meta descriptions. If it takes you more than a couple of minutes to write one, then you’re probably overthinking it.

      5. Use Interesting Words

      Most meta descriptions are pretty boring, at least linguistically speaking. The need to cover so much information in such a limited space doesn’t lend itself well to innovation.

      One way to make your meta descriptions stand out is by using compelling language. To do that, take a look at what other websites are writing for the keywords you want to rank for. Let’s say, for example, that you’re looking for a cast iron pizza recipe.

      A lot of the content will be similar, which means their meta descriptions will share elements as well. However, not all descriptions are equally effective.

      Some examples of cast iron pizza recipes.

      Some of our favorite hits from the above example include the words ‘crispy,’ ‘buttery,’ and ‘chewy.’ There are five results here, but the first and last stand out due to their word choices.

      Think about it this way — if you’re staring at that page trying to decide which recipe to follow, you’ll probably pick the one that sounds more delicious. At that stage, you don’t know how good the recipe will be, so your only indicators are the title tag, picture, and word choice in the meta description.

      Search Result Focus

      When you boil it down, SEO is a competition. You’ll never be the only website within a niche, so you need to look for ways to make your pages stand out in the SERPs. Fortunately, an informative, unique meta description is a great way to catch potential visitors’ eyes.

      Are you looking for a hosting plan that can handle all the traffic your improved meta descriptions will send your way? Check out our shared hosting options!

      Source link

      The Flagship Series: INAP Los Angeles Data Centers

      The Los Angeles data center market is in high demand. Facilities in the second-largest U.S. metro area provide important points of interconnection to data centers in Phoenix, Las Vegas and Silicon Valley, and are vital to supporting the needs of the entertainment, technology, aerospace and biomedical industries.

      To manage colocation environments and reduce latency for end users, data center customers want to be close to their infrastructure and thus are increasingly in search of centrally located real estate. What’s more, L.A. is a key network gateway to Asia Pacific users, boasting some of the most interconnected internet exchange points in the world.

      High demand, however, has resulted in capacity constraints. The L.A. data center market is seeing low vacancy rates and limited construction of new data center space, with only 9.0 MW under construction and only 6.0 MW planned at the end of 2018, according to a recent report from JLL. In comparison, nearby data center hub Phoenix saw 45.0 MW of new space, with 299.8 MW planned. Northern California saw 42.0 MW under construction over this same time period.

      One reason for the limited capacity is the cost of power, partially due to older grids. In markets seeing booming data center growth, energy costs are often half of what customers will see in the L.A. area. However, that desire to be close to the infrastructure, as well as to key network exchanges, will be enough to drive demand for the foreseeable future.

      When deploying in a competitive market like Los Angeles, enterprises must make the most of their data center investment by choosing a provider that can effectively meet unique performance needs and provide an energy efficient environment.

      Considering Los Angeles for a colocation, network or cloud solution? There are several reasons why we’re confident you’ll call INAP your future partner in this competitive market.

      INAP L.A. Data Centers Deliver High-Performance, High-Efficiency Colocation and Network Solutions

      INAP has six data centers and points of presence in the Los Angeles metro area, with our flagship facility located in Redondo Beach at 3690 Redondo Beach Avenue.

      The 105,000 square-foot flagship data center is designed with Tier 3 compliant attributes and offers high-density configurations including cages, cabinets and suites. Each rack offers high power density of 20 kW or more.

      INAP’s L.A. locations connect to Dallas, Phoenix and Silicon Valley through our high-capacity private fiber backbone. The INAP Performance IP® and Connectivity Solutions product suite provides high availability and scalable connectivity services across our global network. Customers can build the high-performance network their applications and users demand.

      The flagship also includes the following features:

      • Power and Space: 4 MW of utility power, 36-inch raised floor, fully integrated critical infrastructure monitoring
      • Facilities: Break rooms, meeting rooms, onsite engineers with remote hands
      • Energy Efficient Cooling: 300 tons of cooling capacity and N+1 with concurrent maintainability
      • Security: 24/7/365 onsite staff, video surveillance, key card and biometric authentication
      • Network: INAP Performance IP® and Connectivity Solutions
      • Compliance: SOC 2 Type II, PCI DSS, HIPAA, Green Globes

      Our recently announced expansion to this data center will offer additional benefits to customers and more space in a market hungry for it.

      Redondo Beach Data Center Expansion

      “Driven by high demand and capacity constraints in the L.A. market, we have seen accelerated growth in our L.A. Flagship dating back to the end of 2017,” said Andrew Day, Chief Operating Officer of INAP. “The expansion illustrates INAP’s unique ability to provide comprehensive, high-performance data center, cloud and network solutions.”

      The data center expansion will begin with a build-out of an additional 12,000 square feet of sellable space. After the build-out, the following phases will add modular infrastructure deployments contingent on customer loads. The expanded facility will use efficient mechanical design combined with an optimized UPS deployment. Total critical power capacity will increase from 1.4 MW to 3.2 MW to support new customer deployments and existing customer growth.

      To help address the cost of power, energy efficiency is of the utmost importance. The expansion to the Redondo Beach  facility will increase energy efficiency to 1.3 PEU effectiveness, a level above the national average of 1.67.

      CHAT NOW

      Spend Portability Meets Changing User Demands

      Organizations need the ability to be agile as their needs change. With INAP Interchange, there’s no need to worry about getting locked into a long-term infrastructure solution that might not be the right fit years down the road.

      There are a variety of business cases for Interchange, including a move from a colocation facility to a bare metal or private cloud environment, or a re-deploy of applications to a new hosted environment. Geographic flexibility is a common reason for a tactical shift. For example, a company based in an INAP data center in L.A. may see an increase for demand in its SaaS solution in in the Southeastern U.S. To be closer to its customers, the company can shift to a custom-engineered solution in one of INAP’s two Flagship data centers in Atlanta.

      Colocation, Bare Metal and Private Cloud solutions are eligible for Interchange. The program allows customers to exchange infrastructure environments a year (or later) into their contract so that they can focus on current-state IT needs while knowing they will be able to adapt for future-state realities.  

      You can learn more about the INAP Interchange by downloading the FAQ.

      Laura Vietmeyer


      Source link